Calculates the free memory of the device. This is based on an inspection of the filesystem, which in android devices is stored in RAM.
//package org.acra.util;
import java.io.File;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Environment;
import android.os.StatFs;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;
/**
* Responsible for providing base utilities used when constructing the report.
* <p/>
* @author William Ferguson
* @since 4.3.0
*/
public final class ReportUtils {
/**
* Calculates the free memory of the device. This is based on an inspection of the filesystem, which in android
* devices is stored in RAM.
*
* @return Number of bytes available.
*/
public static long getAvailableInternalMemorySize() {
final File path = Environment.getDataDirectory();
final StatFs stat = new StatFs(path.getPath());
final long blockSize = stat.getBlockSize();
final long availableBlocks = stat.getAvailableBlocks();
return availableBlocks * blockSize;
}
}
Related examples in the same category