如何以百分比形式使用RAM?

时间:2017-04-09 18:17:41

标签: java android ram

我正在尝试获取已用RAM的百分比,但这段代码只是给了我用MB的二手RAM。我怎么能以百分比得到它?

private void Used(){
    ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
    ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    activityManager.getMemoryInfo(mi);
    long availableMegs = mi.availMem / 1048576L;
    long used = TotalRam() - availableMegs ;
    crpv.setPercent();
    crpv.setPercent(used);
    tvPercent.setText(used+" MB");
}

1 个答案:

答案 0 :(得分:0)

double percentUsed = 1.0 * used / TotalRam();