android 系统内存显示

1、系统总内存

//查看总内存
    private String GetTotalMemory() {
        String str1 = "/proc/meminfo";
        String str2;
        Double memory = 0.0;
        try {
            FileReader r = new FileReader(str1);
            BufferedReader bufferedRead = new BufferedReader(r, 8192);
            str2 = bufferedRead.readLine();
            String str4 = str2.substring(str2.length() - 9, str2.length() - 3);
            memory = Double.parseDouble(str4) / 1000;
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
        return memory+"M";
    } 

2、所剩内存

private String getRestMemory() {    
        final ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); 
        ActivityManager.MemoryInfo info = new ActivityManager.MemoryInfo(); 
        activityManager.getMemoryInfo(info); 
        Log.i("Main:","系统剩余内存:"+(info.availMem >> 10)+"k"); 
        Log.i("Main:","系统是否处于低内存运行:"+info.lowMemory);
        Log.i("Main:","当系统剩余内存低于"+info.threshold+"时就看成低内存运行");
        return (info.availMem >> 10)/1024 + "M " +(info.availMem >> 10)%1024 + "k";
    } 

3、使用

String s = "系统内存:"+GetTotalMemory()+"\n"+"系统剩余内存:"+displayBriefMemory();

你可能感兴趣的:(android)