
Android获取cpu和内存信息、网址的代码如下:
/ 获取用户硬件信息 /
public static String getMobileInfo() {
//StringBuffer sb = new StringBuffer();
JSONObject mbInfo = new JSONObject();
//通过反射获取用户硬件信息
try {
Field[] fields = BuildclassgetDeclaredFields();
for (Field field : fields) {
// 暴力反射,获取私有信息
fieldsetAccessible(true);
String name = fieldgetName();
String value = fieldget(null)toString();
//sbappend(name + "=" + value);
//sbappend("\n");
mbInfoput(name, value);
}
} catch (Exception e) {
eprintStackTrace();
}
//return sbtoString();
return mbInfotoString();
}
static public String getCpuString(){
if(BuildCPU_ABIequalsIgnoreCase("x86")){
return "Intel";
}
String strInfo = "";
try
{
byte[] bs = new byte[1024];
RandomAccessFile reader = new RandomAccessFile("/proc/cpuinfo", "r");
readerread(bs);
String ret = new String(bs);
int index = retindexOf(0);
if(index != -1) {
strInfo = retsubstring(0, index);
} else {
strInfo = ret;
}
}
catch (IOException ex){
exprintStackTrace();
}
return strInfo;
}
static public String getCpuType(){
String strInfo = getCpuString();
String strType = null;
if (strInfocontains("ARMv5")) {
strType = "armv5";
} else if (strInfocontains("ARMv6")) {
strType = "armv6";
} else if (strInfocontains("ARMv7")) {
strType = "armv7";
} else if (strInfocontains("Intel")){
strType = "x86";
}else{
strType = "unknown";
return strType;
}
if (strInfocontains("neon")) {
strType += "_neon";
}else if (strInfocontains("vfpv3")) {
strType += "_vfpv3";
}else if (strInfocontains(" vfp")) {
strType += "_vfp";
}else{
strType += "_none";
}
return strType;
}
/
@hide
@return
/
public static CPUInfo getCPUInfo() {
String strInfo = null;
try
{
byte[] bs = new byte[1024];
RandomAccessFile reader = new RandomAccessFile("/proc/cpuinfo", "r");
readerread(bs);
String ret = new String(bs);
int index = retindexOf(0);
if(index != -1) {
strInfo = retsubstring(0, index);
} else {
strInfo = ret;
}
}
catch (IOException ex)
{
strInfo = "";
exprintStackTrace();
}
CPUInfo info = parseCPUInfo(strInfo);
infomCPUMaxFreq = getMaxCpuFreq();
return info;
}
private final static String kCpuInfoMaxFreqFilePath = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq";
private static int getMaxCpuFreq() {
int result = 0;
FileReader fr = null;
BufferedReader br = null;
try {
fr = new FileReader(kCpuInfoMaxFreqFilePath);
br = new BufferedReader(fr);
String text = brreadLine();
if (text != null) {
result = IntegerparseInt(texttrim());
}
} catch (FileNotFoundException e) {
eprintStackTrace();
} catch (IOException e) {
eprintStackTrace();
} finally {
if (fr != null)
try {
frclose();
} catch (IOException e) {
// TODO Auto-generated catch block
eprintStackTrace();
}
if (br != null)
try {
brclose();
} catch (IOException e) {
// TODO Auto-generated catch block
eprintStackTrace();
}
}
return result;
}
public static class CPUInfo{
public CPUInfo(){
}
public static final int CPU_TYPE_UNKNOWN = 0x00000000;
public static final int CPU_TYPE_ARMV5TE = 0x00000001;
public static final int CPU_TYPE_ARMV6 = 0x00000010;
public static final int CPU_TYPE_ARMV7 = 0x00000100;
public static final int CPU_FEATURE_UNKNOWS = 0x00000000;
public static final int CPU_FEATURE_VFP = 0x00000001;
public static final int CPU_FEATURE_VFPV3 = 0x00000010;
public static final int CPU_FEATURE_NEON = 0x00000100;
public int mCPUType;
public int mCPUCount;
public int mCPUFeature;
public double mBogoMips;
public long mCPUMaxFreq;
}
/
@param cpuInfo
@return
@hide
/
private static CPUInfo parseCPUInfo(String cpuInfo) {
if (cpuInfo == null || ""equals(cpuInfo)) {
return null;
}
CPUInfo ci = new CPUInfo();
cimCPUType = CPUInfoCPU_TYPE_UNKNOWN;
cimCPUFeature = CPUInfoCPU_FEATURE_UNKNOWS;
cimCPUCount = 1;
cimBogoMips = 0;
if (cpuInfocontains("ARMv5")) {
cimCPUType = CPUInfoCPU_TYPE_ARMV5TE;
} else if (cpuInfocontains("ARMv6")) {
cimCPUType = CPUInfoCPU_TYPE_ARMV6;
} else if (cpuInfocontains("ARMv7")) {
cimCPUType = CPUInfoCPU_TYPE_ARMV7;
}
if (cpuInfocontains("neon")) {
cimCPUFeature |= CPUInfoCPU_FEATURE_NEON;
}
if (cpuInfocontains("vfpv3")) {
cimCPUFeature |= CPUInfoCPU_FEATURE_VFPV3;
}
if (cpuInfocontains(" vfp")) {
cimCPUFeature |= CPUInfoCPU_FEATURE_VFP;
}
String[] items = cpuInfosplit("\n");
for (String item : items) {
if (itemcontains("CPU variant")) {
int index = itemindexOf(": ");
if (index >= 0) {
String value = itemsubstring(index + 2);
try {
cimCPUCount = Integerdecode(value);
cimCPUCount = cimCPUCount == 0 1 : cimCPUCount;
} catch (NumberFormatException e) {
cimCPUCount = 1;
}
}
} else if (itemcontains("BogoMIPS")) {
int index = itemindexOf(": ");
if (index >= 0) {
String value = itemsubstring(index + 2);
}
}
}
return ci;
}
/
获取设备内存大小值
@return 内存大小,单位MB
/
public static long getTotalMemory() {
String str1 = "/proc/meminfo";
String str2;
String[] arrayOfString;
long initial_memory = 0;
try {
FileReader localFileReader = new FileReader(str1);
BufferedReader localBufferedReader = new BufferedReader(localFileReader, 8192);
str2 = localBufferedReaderreadLine();
if (str2 != null) {
arrayOfString = str2split("\\s+");
initial_memory = IntegervalueOf(arrayOfString[1])intValue()/1024;
}
localBufferedReaderclose();
return initial_memory;
}
catch (IOException e)
{
return -1;
}
}
/
@hide
@return
/
public CPUInfo getCPUInfo() {
String strInfo = null;
try
{
byte[] bs = new byte[1024];
RandomAccessFile reader = new RandomAccessFile("/proc/cpuinfo", "r");
readerread(bs);
String ret = new String(bs);
int index = retindexOf(0);
if(index != -1) {
strInfo = retsubstring(0, index);
} else {
strInfo = ret;
}
}
catch (IOException ex)
{
strInfo = "";
exprintStackTrace();
}
CPUInfo info = parseCPUInfo(strInfo);
infomCPUMaxFreq = getMaxCpuFreq();
return info;
}
/
获取android CPU类型
@return String CPU类型
/
public static String getCpuModel(){
String cpu_model = "";
CPUInfo in = getCPUInfo();
if ((inmCPUType & CPUInfoCPU_TYPE_ARMV5TE) == CPUInfoCPU_TYPE_ARMV5TE)
cpu_model="armv5";
else if ((inmCPUType & CPUInfoCPU_TYPE_ARMV6) == CPUInfoCPU_TYPE_ARMV6)
cpu_model="armv6";
else if ((inmCPUType & CPUInfoCPU_TYPE_ARMV7) == CPUInfoCPU_TYPE_ARMV7)
cpu_model="armv7";
else
cpu_model="unknown";
return cpu_model;
}
/
获取android CPU特性
@return String CPU特性
/
public static String getCpuFeature(){
String cpu_feature = "";
CPUInfo in = getCPUInfo();
if ((inmCPUFeature & CPUInfoCPU_FEATURE_NEON ) == CPUInfoCPU_FEATURE_NEON)
cpu_feature="neon";
else if ((inmCPUFeature & CPUInfoCPU_FEATURE_VFP ) == CPUInfoCPU_FEATURE_VFP)
cpu_feature="vfp";
else if ((inmCPUFeature & CPUInfoCPU_FEATURE_VFPV3 ) == CPUInfoCPU_FEATURE_VFPV3)
cpu_feature="vfpv3";
else
cpu_feature="unknown";
return cpu_feature;
}
/
获取ip地址
@param mContext Context
@return ip地址字符串
/
public static String getIpAddress(Context mContext) {
String ipAddress = null;
try {
for (Enumeration en = NetworkInterface
getNetworkInterfaces(); enhasMoreElements();) {
NetworkInterface intf = ennextElement();
for (Enumeration enumIpAddr = intf
getInetAddresses(); enumIpAddrhasMoreElements();) {
InetAddress inetAddress = enumIpAddrnextElement();
if (!inetAddressisLoopbackAddress()) {
ipAddress = inetAddressgetHostAddress()toString();
}
}
}
} catch (SocketException ex) {
return null;
}
if (DEBUG) {
Logd(TAG, "ip address:" + ipAddress);
}
return ipAddress;
}
尊敬的用户您好,从P III以后CPU不支持序列号了,可以读取CPU名字之类的。
一般用WMI读就行,硬盘的话,也可以直接读取SMART。
写过一个,留下邮箱,给你发过去。
希望可以帮到您
以上就是关于怎么获得CPU的信息全部的内容,包括:怎么获得CPU的信息、c++语言获取cpu序列号,网上找的用汇编的都是有问题的,每台电脑取的都一样。懂的高手指教、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)