1原理:

根据系统基本配置文件build.prop获取华为的ROM等级,知道了等级就知道是否是华为的手机了。

2代码:

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;

}

}

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐