Skip to content

Instantly share code, notes, and snippets.

@mitchross
Created November 17, 2015 19:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mitchross/b012bd72a9cd3b1f92c7 to your computer and use it in GitHub Desktop.
Save mitchross/b012bd72a9cd3b1f92c7 to your computer and use it in GitHub Desktop.
public class MemoryUtility
{
public static long getTotalInternalMemory( Context context )
{
long totalSpace = new File(context.getFilesDir().getAbsoluteFile().toString()).getTotalSpace();
return totalSpace;
}
public static long getTotalUnusedMemory( Context context )
{
long freeBytesInternal = new File(context.getFilesDir().getAbsoluteFile().toString()).getFreeSpace();
return freeBytesInternal;
}
public static float getPercentageMemoryFree(Context context)
{
long total = getTotalInternalMemory(context);
long avail = getTotalUnusedMemory(context);
float percentage = ((float)avail / (float)total);
return percentage;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment