Android获取CPU信息(CPU名字和主频)
来源:互联网 发布:淘宝店铺图片尺寸要求 编辑:程序博客网 时间:2024/05/03 18:39
文章参照自:http://www.2cto.com/kf/201206/134236.html
在Android中,我们可以通过读取一些系统文件来获得手机的cpu信息(CPU名字和CPU主频)。具体请参照实例1.
实例1
package edu.cdut.robin;import java.io.BufferedReader;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;public class CPUTool{ private final static String kCpuInfoMaxFreqFilePath = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"; public static int getMaxCpuFreq() { int result = 0; FileReader fr = null; BufferedReader br = null; try { fr = new FileReader(kCpuInfoMaxFreqFilePath); br = new BufferedReader(fr); String text = br.readLine(); result = Integer.parseInt(text.trim()); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (fr != null) try { fr.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (br != null) try { br.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return result; } private final static String kCpuInfoMinFreqFilePath = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq"; /* 获取CPU最小频率(单位KHZ) */ public static int getMinCpuFreq() { int result = 0; FileReader fr = null; BufferedReader br = null; try { fr = new FileReader(kCpuInfoMinFreqFilePath); br = new BufferedReader(fr); String text = br.readLine(); result = Integer.parseInt(text.trim()); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (fr != null) try { fr.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (br != null) try { br.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return result; } private final static String kCpuInfoCurFreqFilePath = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq"; /* 实时获取CPU当前频率(单位KHZ) */ public static int getCurCpuFreq() { int result = 0; FileReader fr = null; BufferedReader br = null; try { fr = new FileReader(kCpuInfoCurFreqFilePath); br = new BufferedReader(fr); String text = br.readLine(); result = Integer.parseInt(text.trim()); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (fr != null) try { fr.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (br != null) try { br.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return result; } /* 获取CPU名字 */ public static String getCpuName() { FileReader fr = null; BufferedReader br = null; try { fr = new FileReader("/proc/cpuinfo"); br = new BufferedReader(fr); String text = br.readLine(); String[] array = text.split(":\\s+", 2); for (int i = 0; i < array.length; i++) { } return array[1]; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (fr != null) try { fr.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (br != null) try { br.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return null; }}
结束
- Android获取CPU信息(CPU名字和主频)
- Android获取CPU信息(CPU名字和主频)
- unity3d 获取cpu主频 android
- C#获取CPU主频等信息
- 获取cpu主频
- 如何获取CPU的主频和使用率?
- 【获取系统信息】4,获取CPU名称、主频
- android获取cpu信息
- CPU : 什么是CPU主频
- 如何获取CPU主频----读注册表
- android cpu信息的获取
- android手机获取cpu信息
- 获取内存和CPU信息
- CPU主频和外频的性能指标
- cpu的主频、外频和倍频
- Java 获取操作系统名字、系统版本、cpu信息
- Android获取系统信息---获取CPU数
- 编程计算CPU主频
- hdu 1969 pie
- 黑马程序员-java IO流
- 程序员写博客的缘由
- 你真的愿意到了50岁还要做编程吗?
- Java连接SQL Sever 2005
- Android获取CPU信息(CPU名字和主频)
- 国外程序员推荐:每个程序员都应读的书
- hibernate教程:1、hibernate入门
- 《货币》记录片--绪论
- 红黑树实现 实现代码
- 浅谈磁盘空间管理的组成链接法
- 合理规划创建数据库
- 向刘邦学习什么?
- 网站统计中的数据收集原理及实现