Android examples for Hardware:CPU Information
get Cpu Info Architecture
//package com.java2s; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.HashMap; public class Main { private static boolean sHasInitCpuInfo = false; private static String sCpuInfoArch = ""; private static String sCpuInfoVfp = ""; private static String sCpuArchit = ""; public static String getCpuInfoArchit() { initCpuInfo();//from w w w . ja va2s . c o m return sCpuArchit; } /** * Processor : ARMv7 Processor rev 0 (v7l) processor : 0 BogoMIPS : 996.14 processor : 1 BogoMIPS : 996.14 Features : swp half thumb fastmult vfp edsp vfpv3 vfpv3d16 CPU implementer : 0x41 CPU architecture: 7 CPU variant : 0x1 CPU part : 0xc09 CPU revision : 0 Hardware : star Revision : 0000 Serial : 0000000000000000 */ private static void initCpuInfo() { if (sHasInitCpuInfo) { return; } BufferedReader bis = null; try { bis = new BufferedReader(new FileReader(new File( "/proc/cpuinfo"))); HashMap<String, String> cpuInfoMap = new HashMap<String, String>(); String line; while ((line = bis.readLine()) != null) { line = line.trim(); if (line.length() > 0) { String[] pairs = line.split(":"); if (pairs.length > 1) { cpuInfoMap.put(pairs[0].trim(), pairs[1].trim()); } } } String processor = cpuInfoMap.get("Processor"); if (processor != null) { int index1 = processor.indexOf("("); int index2 = processor.lastIndexOf(")"); int len = index2 - index1; if (index1 > 0 && index2 > 0 && len > 0) { sCpuInfoArch = processor.substring(index1 + 1, index2); } else { sCpuInfoArch = "v" + cpuInfoMap.get("CPU architecture"); } } sCpuInfoVfp = cpuInfoMap.get("Features"); sCpuArchit = cpuInfoMap.get("CPU part"); sHasInitCpuInfo = true; } catch (Exception e) { } finally { try { if (bis != null) bis.close(); } catch (IOException e) { } } } }