Runtime方式
private fun getAppMemoryInfo() {
val runtime = Runtime.getRuntime()
println(
"freeMemory================================" +
runtime.freeMemory() / 1024 / 1024
)
println(
"totalMemory================================" +
runtime.totalMemory() / 1024 / 1024
)
println(
"maxMemory================================" +
runtime.maxMemory() / 1024 / 1024
)
}
ActivityManager方式
private fun getRAMMemoryInfo() {
val activityManager =
this.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
val memoryInfo = ActivityManager.MemoryInfo()
activityManager.getMemoryInfo(memoryInfo)
println("totalMem================================" + memoryInfo.totalMem / 1024 / 1024)
println("availMem================================" + memoryInfo.availMem / 1024 / 1024)
println("lowMemory================================" + memoryInfo.lowMemory)
}