【发布时间】:2018-01-29 05:09:43
【问题描述】:
由于 pre android 6.0 权限等问题,我需要知道我的应用程序是否在运行时在 MIUI 设备(如 XIAOMI)上运行。
有什么办法吗?
【问题讨论】:
标签: android runtime-permissions miui
由于 pre android 6.0 权限等问题,我需要知道我的应用程序是否在运行时在 MIUI 设备(如 XIAOMI)上运行。
有什么办法吗?
【问题讨论】:
标签: android runtime-permissions miui
我在 github 上找到了一个旨在做到这一点的要点,方法是尝试获取“ro.miui.ui.version.name”系统属性。
public static boolean isMiUi() {
return !TextUtils.isEmpty(getSystemProperty("ro.miui.ui.version.name"));
}
public static String getSystemProperty(String propName) {
String line;
BufferedReader input = null;
try {
java.lang.Process p = Runtime.getRuntime().exec("getprop " + propName);
input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024);
line = input.readLine();
input.close();
} catch (IOException ex) {
return null;
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return line;
}
【讨论】: