admin管理员组文章数量:1540626
通过反射和进程读取两种方式获取:
MIUI:ro.miui.ui.version.name
EMUI:ro.build.version.emui
反射
public static String getSystemProperty(String propName) {
Class> classType = null;
String buildVersion = null;
try {
classType = Class.forName("android.os.SystemProperties");
Method getMethod = classType.getDeclaredMethod("get", new Class>[]{String.class});
buildVersion = (String) getMethod.invoke(classType, new Object[]{propName});
} catch (Exception e) {
e.printStackTrace();
}
return buildVersion;
}
读取进程
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)
{
Log.e("lth", "Unable to read sysprop " + propName, ex);
return null;
}
finally
{
if(input != null)
{
try
{
input.close();
}
catch (IOException e)
{
Log.e("lth", "Exception while closing InputStream", e);
}
}
}
return line;
}
版权声明:本文标题:android获取MIUI版本号,MIUI 和 EMUI 系统版本号获取 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1727030303a1094776.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论