get Total Memory - Android Hardware

Android examples for Hardware:Memory

Description

get Total Memory

Demo Code


//package com.java2s;
import java.io.BufferedReader;

import java.io.FileReader;
import java.io.IOException;

public class Main {

    public static long getTotalMemory() {
        String str1 = "/proc/meminfo";
        String str2;// w  ww .j  a va  2  s  .  c  o m
        String[] arrayOfString;
        long initial_memory = 0;
        try {
            FileReader localFileReader = new FileReader(str1);
            BufferedReader localBufferedReader = new BufferedReader(
                    localFileReader, 8192);
            str2 = localBufferedReader.readLine();
            if (str2 != null) {
                arrayOfString = str2.split("\\s+");
                initial_memory = Integer.valueOf(arrayOfString[1])
                        .intValue() / 1024;
            }
            localBufferedReader.close();
            return initial_memory;
        } catch (IOException e) {
            return -1;
        }
    }
}

Related Tutorials