Android 如何获得设备中的总内存 RAM? [英] Android How do you get total memory RAM in the device?

查看:88
本文介绍了Android 如何获得设备中的总内存 RAM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过以下方式获得总可用内存:

I can get total available memory by:

ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);
memoryInfo.availMem;

但是,您如何获得设备的总内存 (RAM)?

However, how do you get Total memory (RAM) of the device?

我确实读过:如何发现我的应用程序在 Android 中的内存使用情况?

似乎添加 pidMemoryInfo.getTotalPss() 也不会给我总内存.

It doesn't seem like adding pidMemoryInfo.getTotalPss() gives me the total memory either.

推荐答案

试试这个对我有用.

public static String getTotalRAM() {
    RandomAccessFile reader = null;
    String load = null;
    try {
        reader = new RandomAccessFile("/proc/meminfo", "r");
        load = reader.readLine();
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        // Streams.close(reader);
    }
    return load;
}

这篇关于Android 如何获得设备中的总内存 RAM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆