How to Get CPU Information on Android Android上获取cpu信息

16 篇文章 0 订阅

    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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值