已解决:
public class Space extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.space);
TextView totalM = (TextView)findViewById(R.id.totalMemory);
TextView usedM = (TextView)findViewById(R.id.usedMemory);
TextView freeM = (TextView)findViewById(R.id.freeMemory);
Runtime runtime = Runtime.getRuntime();
try {
Process process = runtime.exec("mem_profiler");
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
String str = in.readLine();
str = str.substring(str.indexOf(":")+1);
totalM.setText("总空间大小: "+str);
str = in.readLine();
str = str.substring(str.indexOf(":")+1);
usedM.setText("已使用空间大小: "+str);
str = in.readLine();
str = str.substring(str.indexOf(":")+1);
freeM.setText("剩余空间大小: "+str);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}