Android Utililty Methods SDCard Check

List of utility methods to do SDCard Check

Description

The list of methods to do SDCard Check are organized into topic(s).

Method

booleanhasMountSDCard()
Detect whether SD card has mounted or not.
return android.os.Environment.getExternalStorageState().equals(
        android.os.Environment.MEDIA_MOUNTED);
longgetExternalStorageFreeSize()
Obtain SD card free size.
final StatFs statfs = new StatFs(Environment
        .getExternalStorageDirectory().getAbsolutePath());
final long availableBlocks = statfs.getAvailableBlocks();
final long blockSize = statfs.getBlockSize();
return availableBlocks * blockSize;
longgetExternalStorageTotalSize()
Obtain SD card total size.
final StatFs statfs = new StatFs(Environment
        .getExternalStorageDirectory().getAbsolutePath());
final long blockCount = statfs.getBlockCount();
final long blockSize = statfs.getBlockSize();
return blockCount * blockSize;
voidgenerateLogOnSD(String sBody, String fileName, String folderName)
public static void generateLogOnSD(String sBody, String fileName, String folderName)

this method can be used to write file on sd card.
try {
    Log.d(TAG, "inside generateLogOnSD");
    if (isExternalStoragePresent()) {
        File file = new File(
                Environment.getExternalStorageDirectory(),
                folderName);
        if (!file.exists()) {
            file.mkdirs();
...
StringgetDataFilesDir(Context c)
get Data Files Dir
return c.getFilesDir().getAbsolutePath() + File.separator;
StringgetSDPath()
get SD Path
String path = null;
if (hasSdcard()) {
    File f = Environment.getExternalStorageDirectory();
    path = f.toString();
return path;
StringgetSdCacheDir(Context context)
get Sd Cache Dir
if (Environment.getExternalStorageState().equals(
        Environment.MEDIA_MOUNTED)) {
    java.io.File fExternalStorageDirectory = Environment
            .getExternalStorageDirectory();
    java.io.File autonaviDir = new java.io.File(
            fExternalStorageDirectory, "amapsdk");
    boolean result = false;
    if (!autonaviDir.exists()) {
...
StringgetSdcardFilesDir(Context c)
get Sdcard Files Dir
return c.getExternalFilesDir(null).getAbsolutePath()
        + File.separator;
booleanhasSdcard()
has Sdcard
String status = Environment.getExternalStorageState();
if (status.equals(Environment.MEDIA_MOUNTED))
    return true;
else
    return false;
booleanisSDCardPresent()
is SD Card Present
return android.os.Environment.getExternalStorageState().equals(
        android.os.Environment.MEDIA_MOUNTED);