Reputation: 1514
I execute /proc/cpuinfo
to get the details of CPU in android device using the below code.
try {
Process proc = Runtime.getRuntime().exec("cat /proc/cpuinfo");
InputStream is = proc.getInputStream();
TextView tv = (TextView)rootView.findViewById(R.id.textView1);
tv.setText(getStringFromInputStream(is));
}
catch (IOException e) {
Log.e("TAG", "------ getCpuInfo " + e.getMessage());
}
Within this it also returns Hardware Name. The Hardware name which I get is not in proper readable Format. I have tested this in various devices like Samsung Note 3, Micromax Canvas Doodle A111, Micromax Turbo A250.
This is what I get in these devices respectively:
How can I overcome this, Please Help !!!
Upvotes: 5
Views: 4651
Reputation: 8415
It seems a bit unclear to me if that you CPU capabilities or device information in general, but anyway...
Android provides a nice little class called Build which gets you quite a bit of information directly via the static fields of the class. This class provides a lot of device-level information as shown below:
Taken directly from my HTC One M8 (some fields omitted):
Build.BOARD: MSM8974
Build.BOOTLOADER: 3.19.0.0000
Build.BRAND: htc
Build.DEVICE: htc_m8
Build.DISPLAY: cm_m8-userdebug 5.1.1 LMY47V 47d6aee9c3 test-keys
Build.HARDWARE: qcom
Build.MANUFACTURER: htc
Build.MODEL: One M8
Build.PRODUCT: cm_m8
From the looks of it Build.BRAND + " " + Build.MODEL
looks like what you want.
Whilst the docs doesn't guarantee any standardization for any field, this is likely to be better than calling Runtime.exec("cat /proc/cpuinfo")
and parsing from there.
If CPU level capabilities is what you want, you can try doing from native code using android cpufeatures library, calling the function:
uint64_t android_getCpuFeatures();
to get a int containing many CPU feature flags.
Upvotes: 2