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

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

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

我确实读过:
How do I discover memory usage of my application in Android?

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

最佳答案

试试这个对我有用。

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;
}

10-04 10:10