有没有办法检查Android设备是否是双核心? (Runtime.availableProcessors()
除外,因为它只会偶尔报告正确的数字。)
我需要它,因为SoundPool不适用于双核(请参阅http://code.google.com/p/android/issues/detail?id=17623)
答案 0 :(得分:0)
尝试这样的事情:
float ALOUD_MISTAKE = 20; // percent
int WORK_TIME = 1000; // milliseconds
public int work(){
int workCounter = 0;
long startTime = System. currentTime();
long currentTime = System. currentTime();
while(startTime < currentTime + WORK_TIME){
currentTime = System. currentTime();
workCounter++;
}
return workCounter;
}
start mainThread1;
check the work time and save it(keep it going)
now start new thread
new Thread(new Runnable(){
void run(){
while(true){
work();
}
}
}).start();
让他们跑一点然后检查:
if(Math.abs(workTimeThread1 - savedWorkTimeThread1) / workTimeThread1 * 100 > ALOUD_MISTAKE)
{
you got (number of new threads been started - 1) cores
}
答案 1 :(得分:0)
在此处https://stackoverflow.com/a/4875506/737925
查看此答案private String ReadCPUinfo()
{
ProcessBuilder cmd;
String result="";
try{
String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
cmd = new ProcessBuilder(args);
Process process = cmd.start();
InputStream in = process.getInputStream();
byte[] re = new byte[1024];
while(in.read(re) != -1){
System.out.println(new String(re));
result = result + new String(re);
}
in.close();
} catch(IOException ex){
ex.printStackTrace();
}
return result;
}
}`
答案 2 :(得分:-1)
我认为Runtime.availableProcessors()
是实现目标的方法。 documentation说:
向虚拟机[...]返回至少为1的处理器可用的数量。
我认为此函数的结果会返回逻辑核心(非物理)的数量。
但这并不能解决您的问题:Bug报告指出该错误只发生在三星Galaxy S2上,我认为它将在未来某个时候修复。