posso ottenere la memoria RAM utilizzabile in modo tale
public String getTotalRAM() {
RandomAccessFile reader = null;
String load = null;
DecimalFormat twoDecimalForm = new DecimalFormat("#.##");
double totRam = 0;
String lastValue = "";
try {
reader = new RandomAccessFile("/proc/meminfo", "r");
load = reader.readLine();
// Get the Number value from the string
Pattern p = Pattern.compile("(\\d+)");
Matcher m = p.matcher(load);
String value = "";
while (m.find()) {
value = m.group(1);
// System.out.println("Ram : " + value);
}
reader.close();
totRam = Double.parseDouble(value);
// totRam = totRam/1024;
double mb = totRam/1024.0;
double gb = totRam/1048576.0;
double tb = totRam/1073741824.0;
if (tb > 1) {
lastValue = twoDecimalForm.format(tb).concat(" TB");
} else if (gb > 1) {
lastValue = twoDecimalForm.format(gb).concat(" GB");
} else if (mb > 1) {
lastValue = twoDecimalForm.format(mb).concat(" MB");
} else {
lastValue = twoDecimalForm.format(totRam).concat(" KB");
}
} catch (IOException ex) {
ex.printStackTrace();
} finally {
// Streams.close(reader);
}
return lastValue;
}
Testato Fino Android 4.3: SAMSUNG S3
fonte
2014-05-07 04:36:21
'public static synchronized int readTotalRam() { \t \t int tm = 1000; \t try { \t RandomAccessFile reader = new RandomAccessFile ("/ proc/meminfo", "r"); \t String load = reader.readLine(); \t Stringa [] totrm = load.split ("kB"); \t Stringa [] trm = totrm [0] .split (""); \t tm = Integer.parseInt (trm [trm.length-1]); \t tm = Math.round (tm/1024); \t} catch (IOException ex) { \t ex.printStackTrace(); \t} \t ritorno tm; \t} ' – BOOMik
Scrivo la funzione per questo. ^^^ answer ^^^ – BOOMik