1原理:
根据系统基本配置文件build.prop获取华为的ROM等级,知道了等级就知道是否是华为的手机了。
2代码:
<span style="font-size:18px;">package com.example.uitest;
import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;
import android.os.Environment;
public class Util {
static int level = 0;
public static int getEmuiLeval() {
// Finals 2016-6-14 如果获取过了就不用再获取了,因为读取配置文件很慢
if (level > 0) {
return level;
}
Properties properties = new Properties();
File propFile = new File(Environment.getRootDirectory(), "build.prop");
FileInputStream fis = null;
if (propFile != null && propFile.exists()) {
try {
fis = new FileInputStream(propFile);
properties.load(fis);
fis.close();
fis = null;
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fis != null) {
try {
fis.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
}
if (properties.containsKey("ro.build.hw_emui_api_level")) {
String valueString = properties.getProperty("ro.build.hw_emui_api_level");
try {
level = Integer.parseInt(valueString);
} catch (Exception e) {
e.printStackTrace();
}
}
return level;
}
}</span><span style="font-weight: bold; font-size: 32px;">
</span>
本文介绍了一种通过读取build.prop文件来获取华为手机EMUI版本的方法。此方法利用Java代码实现,首先检查是否已缓存过版本信息以提高效率,接着尝试从系统根目录下的build.prop文件中读取特定属性。
2069

被折叠的 条评论
为什么被折叠?



