2

I want to get total and used/free ram, my code works fine on all android versions for getting total ram. But I want to get either free or used ram. How do I do that?? There are other questions like this but none of them works on all API levels. the documentation says memoryinfo class was added in API 16.

private String getTotalRAM() {
    RandomAccessFile reader = null;
    String load = null;
    long total = 0;
    try {
        reader = new RandomAccessFile("/proc/meminfo", "r");
        load = reader.readLine().replaceAll("\\D+", "");
        ;
        total = Integer.parseInt(load) / 1024;
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return total + " MB";
}
Mykola
  • 3,152
  • 6
  • 20
  • 39

0 Answers0