CPU信息读取
来源:互联网 发布:mysql bit类型 默认值 编辑:程序博客网 时间:2024/04/29 06:58
Question: 读取/proc, /sys/的相关信息,普通APP应该是无法完成的吧?可能需要platform签名
文章参照自: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; }}
结束
- 读取CPU信息
- 读取CPU信息。
- 读取CPU信息
- CPU信息读取
- 读取qualcom cpu 信息
- 注册表读取CPU信息
- Android 读取CPU信息方法
- c++ 读注册表信息 读取CPU信息
- c# 读取机器CPU信息,硬盘信息,网卡信息
- 自己写的读取CPU信息
- C# 读取计算机CPU,HDD信息
- C# 读取计算机CPU,HDD信息
- 读取CPU和内存使用信息
- 通过读取/proc/cpuinfo获取CPU信息
- 工程项目CPU卡读取数据信息。
- linux下 用cpuid指令读取CPU信息
- linux下 用cpuid指令读取CPU信息
- java读取计算机CPU、内存等信息(Sigar使用)
- centos 安装nginx 配置nginx
- ODBC、JDBC、OLE DB、 ADO、ODAC、ODP.NET介绍
- 温故知新--线程与进程的区别
- cgi
- ZOJ 2001 Adding Reversed Numbers
- CPU信息读取
- 日清日结工作方法简介(OEC)
- Android 模拟器运行OpenGL ES 2
- 实现“摇一摇”功能
- Zephyr:取代HOME键的多任务手势工具
- windows核心编程 如何等待超过64 kernal object
- oracle取得数据的长度字节数
- 数据交换
- Android自动化测试之环境搭建(二)