1、最简单的是使用Build的信息。
import android.os.Build;
String cpu = Build.CPU_ABI;
cpu.startWith("arm");
2、使用系统文件/proc/cpuinfo
- try {
- InputStream is = new FileInputStream("/proc/cpuinfo");
- InputStreamReader ir = new InputStreamReader(is);
- BufferedReader br = new BufferedReader(ir);
- try {
- String nameProcessor = "Processor";
- String nameFeatures = "Features";
- String nameModel = "model name";
- String nameCpuFamily = "cpu family";
- while (true) {
- String line = br.readLine();
- String[] pair = null;
- if (line == null) {
- break;
- }
- pair = line.split(":");
- if (pair.length != 2)
- continue;
- String key = pair[0].trim();
- String val = pair[1].trim();
- if (key.compareTo(nameProcessor) == 0) {
- String n = "";
- for (int i = val.indexOf("ARMv") + 4; i < val.length(); i++) {
- String temp = val.charAt(i) + "";
- if (temp.matches("\\d")) {
- n += temp;
- } else {
- break;
- }
- }
- mArmArchitecture[0] = "ARM";
- mArmArchitecture[1] = Integer.parseInt(n);
- continue;
- }
- if (key.compareToIgnoreCase(nameFeatures) == 0) {
- if (val.contains("neon")) {
- mArmArchitecture[2] = "neon";
- }
- continue;
- }
- if (key.compareToIgnoreCase(nameModel) == 0) {
- if (val.contains("Intel")) {
- mArmArchitecture[0] = "INTEL";
- mArmArchitecture[2] = "atom";
- }
- continue;
- }
- if (key.compareToIgnoreCase(nameCpuFamily) == 0) {
- mArmArchitecture[1] = Integer.parseInt(val);
- continue;
- }
- }
- } finally {
- br.close();
- ir.close();
- is.close();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }