I\'m trying to find a way to find the total size and free space of a mounted SD card on a phone, from my research on SOF and on the Android devs site I was able to find the
public String[] getSize() throws IOException {
String memory="";
Process p = Runtime.getRuntime().exec("df /mnt/sdcard");
InputStream is =p.getInputStream();
int by=-1;
while((by=is.read())!=-1) {
memory+=new String(new byte[]{(byte)by});
}
for (String df:memory.split("/n")) {
if(df.startsWith("/mnt/sdcard")) {
String[] par = df.split(" ");
List pp=new ArrayList();
for(String pa:par) {
if(!pa.isEmpty()) {
pp.add(pa);
}
}
return pp.toArray(new String[pp.size()]);
}
}
return null;
}
getSize()[0] is /mnt/sdcard. getSize()[1] is size of sd (example 12.0G), getSize()[2] is used, [3] is free, [4] is blksize
Or:
new File("/sdcard/").getFreeSpace() - bytes of free in long
new File("/sdcard/").getTotalSpace() - size of sd