打印

求教:如何获得手机上的总空间大小和剩余空间

求教:如何获得手机上的总空间大小和剩余空间

RT

TOP

点击运行cmd, 进入模拟器下tools文件夹,输入 adb shell mem_profiler,屏幕上会显示使用空间以及剩余空间

TOP

回复 2# 的帖子

谢谢。我想在代码里写获取总空间和使用空间的程序,在模拟器界面上显示出来,请问该怎么做呢?

TOP

已解决:
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();
                }
        }

}

TOP