識(shí)別是否是MIUI
根據(jù)MIUI開發(fā)者文檔中的提示
請(qǐng)使用android.os.Build對(duì)象酝豪,查詢MANUFACTURER和MODEL的值卦停,MANUFACTURER值為[Xiaomi]即為小米設(shè)備琴昆,MODEL為設(shè)備名稱,比如[Redmi 4X]表示紅米4X囚戚。
其實(shí)讀的屬性是
[ro.product.manufacturer]: [Xiaomi]
[ro.product.model]: [Redmi 4X]
識(shí)別版本號(hào)
然后在adb shell 之后getprop可以得到一個(gè)屬性『ro.miui.version.code_time』磁携,這個(gè)屬性是一個(gè)毫秒值,對(duì)應(yīng)的是MIUI開發(fā)版的版本號(hào)鉴吹,比如我的MIUI9開發(fā)版7.8.10對(duì)應(yīng)的:
[ro.miui.ui.version.name]: [V9]
表示版本號(hào)為 MIUI9
[ro.miui.version.code_time]: [1502294400]
1502294400毫秒值轉(zhuǎn)換為時(shí)間:2017/8/10姨伟,表示版本為7.8.10
實(shí)現(xiàn)代碼
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;
}