android怎么检测 cpu 硬件信息的
不是从cpuinfo里读的
像安兔兔这种是怎么实现的?
我说的是java 代码的实现
android怎么检测 cpu 硬件信息的
答案:2 悬赏:70 手机版
解决时间 2021-12-26 00:50
- 提问者网友:一抹荒凉废墟
- 2021-12-25 04:07
最佳答案
- 五星知识达人网友:人類模型
- 2021-12-25 04:35
直接查看本机操作系统的详细信息,包话SD卡容量,CPU型号、频率,系统版本号等多项信息,且一键运行完整测试项目,通过“内存性能”、“CPU整数性能”,“CPU浮点性能”、“2D、3D绘图性能”、“数据库IO”、“SD卡读、写速度” 8项性能测试,对手机的硬件性能做一个整体评分
源代码估计是很难找到的,你可以试试在电脑上搭载ADB(android调试桥),然后通过模拟器查看
源代码估计是很难找到的,你可以试试在电脑上搭载ADB(android调试桥),然后通过模拟器查看
全部回答
- 1楼网友:深街酒徒
- 2021-12-25 05:45
android获取cpu和内存信息、网址的代码如下:
public static string getmobileinfo() {
//stringbuffer sb = new stringbuffer();
jsonobject mbinfo = new jsonobject();
//通过反射获取用户硬件信息
try {
field[] fields = build.class.getdeclaredfields();
for (field field : fields) {
// 暴力反射,获取私有信息
field.setaccessible(true);
string name = field.getname();
string value = field.get(null).tostring();
//sb.append(name + "=" + value);
//sb.append("\n");
mbinfo.put(name, value);
}
} catch (exception e) {
e.printstacktrace();
}
//return sb.tostring();
return mbinfo.tostring();
}
static public string getcpustring(){
if(build.cpu_abi.equalsignorecase("x86")){
return "intel";
}
string strinfo = "";
try
{
byte[] bs = new byte[1024];
randomaccessfile reader = new randomaccessfile("/proc/cpuinfo", "r");
reader.read(bs);
string ret = new string(bs);
int index = ret.indexof(0);
if(index != -1) {
strinfo = ret.substring(0, index);
} else {
strinfo = ret;
}
}
catch (ioexception ex){
ex.printstacktrace();
}
return strinfo;
}
static public string getcputype(){
string strinfo = getcpustring();
string strtype = null;
if (strinfo.contains("armv5")) {
strtype = "armv5";
} else if (strinfo.contains("armv6")) {
strtype = "armv6";
} else if (strinfo.contains("armv7")) {
strtype = "armv7";
} else if (strinfo.contains("intel")){
strtype = "x86";
}else{
strtype = "unknown";
return strtype;
}
if (strinfo.contains("neon")) {
strtype += "_neon";
}else if (strinfo.contains("vfpv3")) {
strtype += "_vfpv3";
}else if (strinfo.contains(" vfp")) {
strtype += "_vfp";
}else{
strtype += "_none";
}
return strtype;
}
public static cpuinfo getcpuinfo() {
string strinfo = null;
try
{
byte[] bs = new byte[1024];
randomaccessfile reader = new randomaccessfile("/proc/cpuinfo", "r");
reader.read(bs);
string ret = new string(bs);
int index = ret.indexof(0);
if(index != -1) {
strinfo = ret.substring(0, index);
} else {
strinfo = ret;
}
}
catch (ioexception ex)
{
strinfo = "";
ex.printstacktrace();
}
cpuinfo info = parsecpuinfo(strinfo);
info.mcpumaxfreq = 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 = br.readline();
if (text != null) {
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;
}
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;
}
private static cpuinfo parsecpuinfo(string cpuinfo) {
if (cpuinfo == null || "".equals(cpuinfo)) {
return null;
}
cpuinfo ci = new cpuinfo();
ci.mcputype = cpuinfo.cpu_type_unknown;
ci.mcpufeature = cpuinfo.cpu_feature_unknows;
ci.mcpucount = 1;
ci.mbogomips = 0;
if (cpuinfo.contains("armv5")) {
ci.mcputype = cpuinfo.cpu_type_armv5te;
} else if (cpuinfo.contains("armv6")) {
ci.mcputype = cpuinfo.cpu_type_armv6;
} else if (cpuinfo.contains("armv7")) {
ci.mcputype = cpuinfo.cpu_type_armv7;
}
if (cpuinfo.contains("neon")) {
ci.mcpufeature |= cpuinfo.cpu_feature_neon;
}
if (cpuinfo.contains("vfpv3")) {
ci.mcpufeature |= cpuinfo.cpu_feature_vfpv3;
}
if (cpuinfo.contains(" vfp")) {
ci.mcpufeature |= cpuinfo.cpu_feature_vfp;
}
string[] items = cpuinfo.split("\n");
for (string item : items) {
if (item.contains("cpu variant")) {
int index = item.indexof(": ");
if (index >= 0) {
string value = item.substring(index + 2);
try {
ci.mcpucount = integer.decode(value);
ci.mcpucount = ci.mcpucount == 0 ? 1 : ci.mcpucount;
} catch (numberformatexception e) {
ci.mcpucount = 1;
}
}
} else if (item.contains("bogomips")) {
int index = item.indexof(": ");
if (index >= 0) {
string value = item.substring(index + 2);
}
}
}
return ci;
}
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 = localbufferedreader.readline();
if (str2 != null) {
arrayofstring = str2.split("\\s+");
initial_memory = integer.valueof(arrayofstring[1]).intvalue()/1024;
}
localbufferedreader.close();
return initial_memory;
}
catch (ioexception e)
{
return -1;
}
}
public cpuinfo getcpuinfo() {
string strinfo = null;
try
{
byte[] bs = new byte[1024];
randomaccessfile reader = new randomaccessfile("/proc/cpuinfo", "r");
reader.read(bs);
string ret = new string(bs);
int index = ret.indexof(0);
if(index != -1) {
strinfo = ret.substring(0, index);
} else {
strinfo = ret;
}
}
catch (ioexception ex)
{
strinfo = "";
ex.printstacktrace();
}
cpuinfo info = parsecpuinfo(strinfo);
info.mcpumaxfreq = getmaxcpufreq();
return info;
}
public static string getcpumodel(){
string cpu_model = "";
cpuinfo in = getcpuinfo();
if ((in.mcputype & cpuinfo.cpu_type_armv5te) == cpuinfo.cpu_type_armv5te)
cpu_model="armv5";
else if ((in.mcputype & cpuinfo.cpu_type_armv6) == cpuinfo.cpu_type_armv6)
cpu_model="armv6";
else if ((in.mcputype & cpuinfo.cpu_type_armv7) == cpuinfo.cpu_type_armv7)
cpu_model="armv7";
else
cpu_model="unknown";
return cpu_model;
}
public static string getcpufeature(){
string cpu_feature = "";
cpuinfo in = getcpuinfo();
if ((in.mcpufeature & cpuinfo.cpu_feature_neon ) == cpuinfo.cpu_feature_neon)
cpu_feature="neon";
else if ((in.mcpufeature & cpuinfo.cpu_feature_vfp ) == cpuinfo.cpu_feature_vfp)
cpu_feature="vfp";
else if ((in.mcpufeature & cpuinfo.cpu_feature_vfpv3 ) == cpuinfo.cpu_feature_vfpv3)
cpu_feature="vfpv3";
else
cpu_feature="unknown";
return cpu_feature;
}
public static string getipaddress(context mcontext) {
string ipaddress = null;
try {
for (enumeration en = networkinterface
.getnetworkinterfaces(); en.hasmoreelements();) {
networkinterface intf = en.nextelement();
for (enumeration enumipaddr = intf
.getinetaddresses(); enumipaddr.hasmoreelements();) {
inetaddress inetaddress = enumipaddr.nextelement();
if (!inetaddress.isloopbackaddress()) {
ipaddress = inetaddress.gethostaddress().tostring();
}
}
}
} catch (socketexception ex) {
return null;
}
if (debug) {
log.d(tag, "ip address:" + ipaddress);
}
return ipaddress;
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯