Get Memory Size Strings : Memory « Hardware « Android






Get Memory Size Strings

  
import java.text.DecimalFormat;

class Main{

    /**
     * 
     * @return
     */
    public static String getMemorySizeStrings() {
        
        DecimalFormat dformat = new DecimalFormat("###,###,###,##0");
        String mem = null;
        long freeSize = 0L;
        long totalSize = 0L;
        long usedSize = 0L;
        try {
            Runtime info = Runtime.getRuntime();
            freeSize = info.freeMemory();
            totalSize = info.totalMemory();
            usedSize = totalSize - freeSize;

            mem = "free=" + dformat.format(freeSize) + " byte / " + "total="
                    + dformat.format(totalSize) + " byte / " + "used="
                    + dformat.format(usedSize) + " byte";

        } catch (Exception e) {
            e.printStackTrace();
        }
        return mem;
    }
}

   
    
  








Related examples in the same category

1.Get memory information
2.Get Used Memory Size
3.Get Free Memory Size
4.Get Total Memory Size
5.Calculates the free memory of the device. This is based on an inspection of the filesystem, which in android devices is stored in RAM.
6.Calculates the total memory of the device. This is based on an inspection of the filesystem, which in android devices is stored in RAM.
7.Get Memory Total
8.Get Memory Free
9.get MemoryInfo
10.Memory information