0
我想获取系统的状态,然后显示一个对话框(此时代码很短,代码很短),并允许用户根据目前的状态。获取系统状态(ro或rw)
我用下面的代码,但它没有工作,我很困惑,为什么它不工作。
File system = new File("/system");
if(system.canWrite()){
Toast.makeText(Utilities.this, "System is RW", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(Utilities.this, "System is RO", Toast.LENGTH_SHORT).show();
}
这怎么办?
===============================编辑============= ==================
下面是解析的/ proc /坐骑后的最终代码为未来的搜索
private boolean readReadWriteFile() {
File mountFile = new File("/proc/mounts");
StringBuilder procData = new StringBuilder();
if(mountFile.exists()) {
try {
FileInputStream fis = new FileInputStream(mountFile.toString());
DataInputStream dis = new DataInputStream(fis);
BufferedReader br = new BufferedReader(new InputStreamReader(dis));
String data;
while((data = br.readLine()) != null) {
procData.append(data + "\n");
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
if(procData.toString() != null) {
String[] tmp = procData.toString().split("\n");
for(int x = 0; x < tmp.length; x++) {
//Kept simple here on purpose different devices have different blocks
if(tmp[x].contains("/dev/block") && tmp[x].contains("/system")) {
if(tmp[x].contains("rw")) {
Toast.makeText(Activity.this, "System is rw", Toast.LENGTH_LONG).show();
return true;
} else if(tmp[x].contains("ro")) {
Toast.makeText(Activity.this, "System is ro", Toast.LENGTH_LONG).show();
return false;
} else {
return false;
}
}
}
}
}
return false;
}
好主意没有想到这一点,这应该工作,谢谢一吨的建议 – user577732 2011-05-30 22:30:16