Unlike iPhone, Android devices come with different hardware from different manufacturers. One important difference is the CPU architecture. Although almost all Android devices use ARM CPU, it comes with different versions, including armv5, armv5te, armv6, armv6 with VFP, armv7, armv7 with VFP, armv7 with neon etc.
Most of the time there’s no need for a developer to care about CPU types, but if you are developing CPU intensive apps, e.g. video player,video converter etc, you may want to optimize your code based on CPU types.
Retrieving CPU types on Android devices is actually quite simple. Android is based on Linux, and Linux /proc file system has provided an interface for users to get CPU information — /proc/cpuinfo. So to get the CPU information, you simply read this file. And read this file doesn’t require super user privilege.
To get the CPU info from command line, simple enter the command below,
adb shell (connect to your Android device shell)
cat /proc/cpuinfo (read the CPU info)
If you want to get the CPU info programmatically, use the code below,
private String getInfo() {
StringBuffer sb = new StringBuffer();
sb.append("abi: ").append(Build.CPU_ABI).append("n");
if (new File("/proc/cpuinfo").exists()) {
try {
BufferedReader br = new BufferedReader(new FileReader(new File("/proc/cpuinfo")));
String aLine;
while ((aLine = br.readLine()) != null) {
sb.append(aLine + "n");
}
if (br != null) {
br.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
You can download the entire code from here or get it from my github repo here.
A sample output is as below,
It gives the process type, and features that are supported by it.
my phone /proc/cpuinfo as bellow:
root@android:/ # cat /proc/cpuinfo
Processor : ARMv7 Processor rev 2 (v7l)
processor : 0
BogoMIPS : 13.53
processor : 1
BogoMIPS : 13.53
processor : 2
BogoMIPS : 13.53
processor : 3
BogoMIPS : 13.53
Features : swp half thumb fastmult vfp edsp neon vfpv3 tls vfpv4
CPU implementer : 0x51
CPU architecture: 7
CPU variant : 0x0
CPU part : 0x06f
CPU revision : 2
Hardware : PANTECH APQ8064 EF51K
Revision : 0000
Serial : 0000000000000000