新增获取内存大小
This commit is contained in:
parent
eae7f3d1a0
commit
62f1912a7a
@ -5,6 +5,7 @@ import android.app.ActivityManager;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.text.format.Formatter;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,6 +79,12 @@ public class DeviceUtils {
|
|||||||
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||||
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
|
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
|
||||||
am.getMemoryInfo(mi);
|
am.getMemoryInfo(mi);
|
||||||
return mi.lowMemory;// 将获取的内存大小规格化
|
return mi.lowMemory;
|
||||||
|
}
|
||||||
|
public static String getMemory(Context context) {
|
||||||
|
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||||
|
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
|
||||||
|
am.getMemoryInfo(mi);
|
||||||
|
return Formatter.formatFileSize(context, mi.availMem);// 将获取的内存大小规格化
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user