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

2017-02-17  本文已影响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 后也可以正常编译。

存储空间

上一篇 下一篇

猜你喜欢

热点阅读