判斷MIUI版本及版本號

識別是否是MIUI

根據MIUI開發者文檔中的提示

請使用android.os.Build對象,查詢MANUFACTURER和MODEL的值,MANUFACTURER值為[Xiaomi]即為小米設備,MODEL為設備名稱,比如[Redmi 4X]表示紅米4X。
其實讀的屬性是
[ro.product.manufacturer]: [Xiaomi]
[ro.product.model]: [Redmi 4X]

識別版本號

然后在adb shell 之后getprop可以得到一個屬性『ro.miui.version.code_time』,這個屬性是一個毫秒值,對應的是MIUI開發版的版本號,比如我的MIUI9開發版7.8.10對應的:
[ro.miui.ui.version.name]: [V9]
表示版本號為 MIUI9
[ro.miui.version.code_time]: [1502294400]
1502294400毫秒值轉換為時間:2017/8/10,表示版本為7.8.10

實現代碼

 public static String checkMIUI() {
        String versionCode = "";
        String manufacturer = Build.MANUFACTURER;
        String model = Build.MODEL;
        LogUtils.i("Build.MANUFACTURER = " + manufacturer + " ,Build.MODEL = " + Build.MODEL);
        if (!TextUtils.isEmpty(manufacturer) && manufacturer.equals("Xiaomi")) {
            versionCode = getSystemProperty("ro.miui.version.code_time");
        }
        return versionCode;
    }

    public static String getSystemProperty(String propName) {
        String line;
        BufferedReader input = null;
        try {
            Process p = Runtime.getRuntime().exec("getprop " + propName);
            input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024);
            line = input.readLine();
            input.close();
        } catch (IOException ex) {
            LogUtils.i("Unable to read sysprop " + propName, ex);
            return null;
        } finally {
            if (input != null) {
                try {
                    input.close();
                } catch (IOException e) {
                    LogUtils.i("Exception while closing InputStream", e);
                }
            }
        }
        return line;
    }
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容