美文网首页
Android读取内存和存储使用情况

Android读取内存和存储使用情况

作者: 流水线上的程序员 | 来源:发表于2017-02-17 13:08 被阅读0次

内存空间、

查看内存的可用空间 需要用到ActivityManager这个类,获取系统服务。

ActivityManager manager = (ActivityManager) getSystemService(context.ACTIVITY_SERVICE);

MemoryInfo info = new MemoryInfo();

manager.getMermoryInfo(info);

因为内存使用量的单位是byte,需要用long类型来接收

long memory = info.availMem;// 单位是byte,内存空间当前可用量

long totalMemory = info.totalMem//内存的总量,此获取总量的方式只有在API版本14以下使用会报错,但是clear Lint Markers 后也可以正常编译。

存储空间

相关文章

网友评论

      本文标题:Android读取内存和存储使用情况

      本文链接:https://www.haomeiwen.com/subject/zqokwttx.html