Android 获取处理器型号
Android Get Processor Model
我想获得类似于 DU Booster 的处理器型号。 CPU 型号包含 ARM 处理器版本和修订版。例如:ARMv7 处理器版本 3 (v7l)
我试过了
System.getProperty("os.arch")
return 唯一的架构
和
String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
获取CPU信息。我能够在某些设备中获得正确的信息,但不是全部。
我在 Asus Fonepad 7 上试过,它没有 return 处理器的 属性(但是 returns 处理器(小 p)
它return就像
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 53
model name : Intel(R) Atom(TM) CPU Z2520 @ 1.20GHz
stepping : 1
microcode : 0x10e
cpu MHz : 800.000
cache size : 512 KB
physical id : 0
siblings : 4
我想得到像 "ARMv7 Processor rev 3 (v7l)" 这样的结果。提前致谢..
这是一种简单的方法,您可以使用模式来完成,但这需要大量的 TaE(反复试验)
String unparsed_CPU_INFO;
onCreate{
// cpu info
String result = null;
CMDExecute cmdexe = new CMDExecute();
try {
String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
result = cmdexe.run(args, "/system/bin/");
Log.i("result", "result=" + result);
} catch (IOException ex) {
ex.printStackTrace();
}
unparsed_CPU_INFO = result;
System.out.println("Your cpu model is: " ++ getCPUName());
}
public synchronized String getCPUName() {
if (cpuName == null) {
String CPUName = "";
String[] lines = unparsed_CPU_INFO.split("\n");
for (int i = 0; i < lines.length; i++) {
String temp = lines[i];
if (lines[i].contains("Processor\t:")) {
CPUName = lines[i].replace("Processor\t: ", "");
break;
}
}
cpuName = CPUName;
return CPUName;
} else {
return cpuName;
}
}
您不需要实现单独的方法来处理不同的处理器类型,只需在获取 /proc/cpuinfo
文件时需要时将 model_name
键替换为 cpu_model
即可:
public static Map<String, String> getCPUInfo () throws IOException {
BufferedReader br = new BufferedReader (new FileReader ("/proc/cpuinfo"));
String str;
Map<String, String> output = new HashMap<> ();
while ((str = br.readLine ()) != null) {
String[] data = str.split (":");
if (data.length > 1) {
String key = data[0].trim ().replace (" ", "_");
if (key.equals ("model_name")) key = "cpu_model";
output.put (key, data[1].trim ());
}
}
br.close ();
return output;
}
我想获得类似于 DU Booster 的处理器型号。 CPU 型号包含 ARM 处理器版本和修订版。例如:ARMv7 处理器版本 3 (v7l)
我试过了
System.getProperty("os.arch")
return 唯一的架构
和
String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
获取CPU信息。我能够在某些设备中获得正确的信息,但不是全部。
我在 Asus Fonepad 7 上试过,它没有 return 处理器的 属性(但是 returns 处理器(小 p)
它return就像
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 53
model name : Intel(R) Atom(TM) CPU Z2520 @ 1.20GHz
stepping : 1
microcode : 0x10e
cpu MHz : 800.000
cache size : 512 KB
physical id : 0
siblings : 4
我想得到像 "ARMv7 Processor rev 3 (v7l)" 这样的结果。提前致谢..
这是一种简单的方法,您可以使用模式来完成,但这需要大量的 TaE(反复试验)
String unparsed_CPU_INFO;
onCreate{
// cpu info
String result = null;
CMDExecute cmdexe = new CMDExecute();
try {
String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
result = cmdexe.run(args, "/system/bin/");
Log.i("result", "result=" + result);
} catch (IOException ex) {
ex.printStackTrace();
}
unparsed_CPU_INFO = result;
System.out.println("Your cpu model is: " ++ getCPUName());
}
public synchronized String getCPUName() {
if (cpuName == null) {
String CPUName = "";
String[] lines = unparsed_CPU_INFO.split("\n");
for (int i = 0; i < lines.length; i++) {
String temp = lines[i];
if (lines[i].contains("Processor\t:")) {
CPUName = lines[i].replace("Processor\t: ", "");
break;
}
}
cpuName = CPUName;
return CPUName;
} else {
return cpuName;
}
}
您不需要实现单独的方法来处理不同的处理器类型,只需在获取 /proc/cpuinfo
文件时需要时将 model_name
键替换为 cpu_model
即可:
public static Map<String, String> getCPUInfo () throws IOException {
BufferedReader br = new BufferedReader (new FileReader ("/proc/cpuinfo"));
String str;
Map<String, String> output = new HashMap<> ();
while ((str = br.readLine ()) != null) {
String[] data = str.split (":");
if (data.length > 1) {
String key = data[0].trim ().replace (" ", "_");
if (key.equals ("model_name")) key = "cpu_model";
output.put (key, data[1].trim ());
}
}
br.close ();
return output;
}