Android examples for Hardware:CPU Frequency
Get maximum CPU frequency
//package com.java2s; import java.io.*; public class Main { private static final String CMD_CAT = "/system/bin/cat"; private static final String CPU_FREQ_MAX_PATH = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"; private static long CPU_MAX_frequency = 0; /**//ww w.ja v a2s . c om * Get maximum CPU frequency */ public static long getMaxfrequency() { if (CPU_MAX_frequency > 0) { return CPU_MAX_frequency; } try { CPU_MAX_frequency = Long.parseLong(getCMDOutputString( new String[] { CMD_CAT, CPU_FREQ_MAX_PATH }).trim()); } catch (Exception e) { e.printStackTrace(); } return CPU_MAX_frequency; } /** * Get command output string. */ public static String getCMDOutputString(String[] args) { try { ProcessBuilder cmd = new ProcessBuilder(args); Process process = cmd.start(); InputStream in = process.getInputStream(); StringBuilder sb = new StringBuilder(); byte[] re = new byte[64]; int len; while ((len = in.read(re)) != -1) { sb.append(new String(re, 0, len)); } in.close(); process.destroy(); return sb.toString(); } catch (IOException ex) { ex.printStackTrace(); } return null; } }