1、CPU频率,CPU信息:/proc/cpuinfo和/proc/stat
通过读取文件/proc/cpuinfo系统CPU的类型等多种信息。
读取/proc/stat 所有CPU活动的信息来计算CPU使用率
下面我们就来讲讲如何通过代码来获取CPU频率:
复制代码 代码如下:
package comorangecpu;
import javaioBufferedReader;
import javaioFileNotFoundException;
import javaioFileReader;
import javaioIOException;
import javaioInputStream;
public class CpuManager {
// 获取CPU最大频率(单位KHZ)
// "/system/bin/cat" 命令行
// "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq" 存储最大频率的文件的路径
public static String getMaxCpuFreq() {
String result = "";
ProcessBuilder cmd;
try {
String[] args = { "/system/bin/cat",
"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq" };
cmd = new ProcessBuilder(args);
Process process = cmdstart();
InputStream in = processgetInputStream();
byte[] re = new byte[24];
while (inread(re) != -1) {
result = result + new String(re);
}
inclose();
} catch (IOException ex) {
exprintStackTrace();
result = "N/A";
}
return resulttrim();
}
// 获取CPU最小频率(单位KHZ)
public static String getMinCpuFreq() {
String result = "";
ProcessBuilder cmd;
try {
String[] args = { "/system/bin/cat",
"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq" };
cmd = new ProcessBuilder(args);
Process process = cmdstart();
InputStream in = processgetInputStream();
byte[] re = new byte[24];
while (inread(re) != -1) {
result = result + new String(re);
}
inclose();
} catch (IOException ex) {
exprintStackTrace();
result = "N/A";
}
return resulttrim();
}
// 实时获取CPU当前频率(单位KHZ)
public static String getCurCpuFreq() {
String result = "N/A";
try {
FileReader fr = new FileReader(
"/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq");
BufferedReader br = new BufferedReader(fr);
String text = brreadLine();
result = texttrim();
} catch (FileNotFoundException e) {
eprintStackTrace();
} catch (IOException e) {
eprintStackTrace();
}
return result;
}
// 获取CPU名字
public static String getCpuName() {
try {
FileReader fr = new FileReader("/proc/cpuinfo");
BufferedReader br = new BufferedReader(fr);
String text = brreadLine();
String[] array = textsplit(":s+", 2);
for (int i = 0; i < arraylength; i++) {
}
return array[1];
} catch (FileNotFoundException e) {
eprintStackTrace();
} catch (IOException e) {
eprintStackTrace();
}
return null;
}
}
2、内存:/proc/meminfo
复制代码 代码如下:
public void getTotalMemory() {
String str1 = "/proc/meminfo";
String str2="";
try {
FileReader fr = new FileReader(str1);
BufferedReader localBufferedReader = new BufferedReader(fr, 8192);
while ((str2 = localBufferedReaderreadLine()) != null) {
Logi(TAG, "---" + str2);
}
} catch (IOException e) {
}
}
3、Rom大小
复制代码 代码如下:
public long[] getRomMemroy() {
long[] romInfo = new long[2];
//Total rom memory
romInfo[0] = getTotalInternalMemorySize();
//Available rom memory
File path = EnvironmentgetDataDirectory();
StatFs stat = new StatFs(pathgetPath());
long blockSize = statgetBlockSize();
long availableBlocks = statgetAvailableBlocks();
romInfo[1] = blockSize availableBlocks;
getVersion();
return romInfo;
}
public long getTotalInternalMemorySize() {
File path = EnvironmentgetDataDirectory();
StatFs stat = new StatFs(pathgetPath());
long blockSize = statgetBlockSize();
long totalBlocks = statgetBlockCount();
return totalBlocks blockSize;
}
4、sdCard大小
复制代码 代码如下:
public long[] getSDCardMemory() {
long[] sdCardInfo=new long[2];
String state = EnvironmentgetExternalStorageState();
if (EnvironmentMEDIA_MOUNTEDequals(state)) {
File sdcardDir = EnvironmentgetExternalStorageDirectory();
StatFs sf = new StatFs(sdcardDirgetPath());
long bSize = sfgetBlockSize();
long bCount = sfgetBlockCount();
long availBlocks = sfgetAvailableBlocks();
sdCardInfo[0] = bSize bCount;//总大小
sdCardInfo[1] = bSize availBlocks;//可用大小
}
return sdCardInfo;
}
5、电池电量
复制代码 代码如下:
private BroadcastReceiver batteryReceiver=new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
int level = intentgetIntExtra("level", 0);
// level加%就是当前电量了
}
};
registerReceiver(batteryReceiver, new IntentFilter(IntentACTION_BATTERY_CHANGED));
6、系统的版本信息
复制代码 代码如下:
public String[] getVersion(){
String[] version={"null","null","null","null"};
String str1 = "/proc/version";
String str2;
String[] arrayOfString;
try {
FileReader localFileReader = new FileReader(str1);
BufferedReader localBufferedReader = new BufferedReader(
localFileReader, 8192);
str2 = localBufferedReaderreadLine();
arrayOfString = str2split("s+");
version[0]=arrayOfString[2];//KernelVersion
localBufferedReaderclose();
} catch (IOException e) {
}
version[1] = BuildVERSIONRELEASE;// firmware version
version[2]=BuildMODEL;//model
version[3]=BuildDISPLAY;//system version
return version;
}
7、mac地址和开机时间
复制代码 代码如下:
public String[] getOtherInfo(){
String[] other={"null","null"};
WifiManager wifiManager = (WifiManager) mContextgetSystemService(ContextWIFI_SERVICE);
WifiInfo wifiInfo = wifiManagergetConnectionInfo();
if(wifiInfogetMacAddress()!=null){
other[0]=wifiInfogetMacAddress();
} else {
other[0] = "Fail";
}
other[1] = getTimes();
return other;
}
private String getTimes() {
long ut = SystemClockelapsedRealtime() / 1000;
if (ut == 0) {
ut = 1;
}
int m = (int) ((ut / 60) % 60);
int h = (int) ((ut / 3600));
return h + " " + mContextgetString(Rstringinfo_times_hour) + m + " "
+ mContextgetString(Rstringinfo_times_minute);
}
ROM只读存储器(Read-Only Memory)是一种只能读取资料的存储器。在制造过程中,将资料以一特制光罩(mask)烧录于线路中,其资料内容在写入后就不能更改,所以有时又称为“光罩式只读内存”(mask ROM)。此内存的制造成本较低,常用于电脑中的开机启动如启动光盘,在系统装好的电脑上时,计算机将C盘目录下的 *** 作系统文件读取至内存,然后通过cpu调用各种配件进行工作这时系统存放存储器为RAM。这种属于COMPACT DISC激光唱片,光盘就是这种。
手机有两个内存,一个是ram,一个是rom。具体不同可以百度。
手机提示内存不足是提示ram不足。也就是你把软件安装在ram里边了,ram一般都比rom小,它影响手机的运行速度。建议你把软件都装在sd卡上,这样手机会更流畅。也不会有提示不足了。
游戏说明写着容量512MB,下载下来是20MB
注意你打错了一个字 或者网站写错了
游戏的容量是512Mb 下载的是20MB(压缩包)
b是bit B是Byte
1B=8bit
在储存卡里占用的是512Mb(512Mb/8=64MB)
还有什么问题可以到我空间留言询问
以上就是关于Android获取系统cpu信息,内存,版本,电量等信息全部的内容,包括:Android获取系统cpu信息,内存,版本,电量等信息、ROM大小是什么、android 手机rom大小的问题等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)