To do this pre-API 16 you have to read the proc/meminfo file of the android kernel:
public long getTotalMemory() {
String str1 = "/proc/meminfo";
String str2;
String[] arrayOfString;
long initial_memory = 0;
try {
FileReader localFileReader = new FileReader(str1);
BufferedReader localBufferedReader = new BufferedReader( localFileReader, 8192);
str2 = localBufferedReader.readLine();//meminfo
arrayOfString = str2.split("\\s+");
for (String num : arrayOfString) {
Log.i(str2, num + "\t");
}
//total Memory
initial_memory = Integer.valueOf(arrayOfString[1]).intValue() * 1024;
localBufferedReader.close();
return initial_memory;
}
catch (IOException e)
{
return -1;
}
}
Source: this question
However, in API 16 and onward, you can use the following code to retrieve the total memory:
ActivityManager actManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
MemoryInfo memInfo = new ActivityManager.MemoryInfo();
actManager.getMemoryInfo(memInfo);
long totalMemory = memInfo.totalMem;