안드로이드 RAM 사용량 구하기 , 전체 RAM 용량 , 사용가능 RAM 용량


MainActivity.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    //RAM 사용량 구하기
    public String getRamUsageRate(){
        //Ram 사용량 구하기
        ActivityManager activityManager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
        ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
 
        activityManager.getMemoryInfo(memoryInfo);
        //전체 RAM용량
        double totalMem = memoryInfo.totalMem;  //API 16부터
        //사용가능한 RAM용량
        double availMem = memoryInfo.availMem;
 
        //사용량
        DecimalFormat df = new DecimalFormat("#,###");
        double ram = 100*(totalMem-availMem)/totalMem;
        return df.format(ram)+"%";
    }
cs



결과


+ Recent posts