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

booleanenoughSpaceOnPhone(long updateSize)
enough Space On Phone
return getRealSizeOnPhone() > updateSize;
booleanenoughSpaceOnSdCard(long updateSize)
enough Space On Sd Card
String status = Environment.getExternalStorageState();
if (!status.equals(Environment.MEDIA_MOUNTED))
    return false;
return (updateSize < getRealSizeOnSdcard());
longgetRealSizeOnPhone()
get Real Size On Phone
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
long realSize = blockSize * availableBlocks;
return realSize;
longgetRealSizeOnSdcard()
get Real Size On Sdcard
File path = new File(Environment.getExternalStorageDirectory()
        .getAbsolutePath());
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return availableBlocks * blockSize;
booleanhasExternalCacheDir()
has External Cache Dir
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO;
booleanhasSDCard()
has SD Card
String status = Environment.getExternalStorageState();
if (!status.equals(Environment.MEDIA_MOUNTED)) {
    return false;
return true;
booleanhasSDCard()
has SD Card
return Environment.MEDIA_MOUNTED.equals(Environment
        .getExternalStorageState());
booleansdCardIsAvailable()
sd Card Is Available
String status = Environment.getExternalStorageState();
if (!status.equals(Environment.MEDIA_MOUNTED)) {
    return false;
return true;
booleanisExternalStorageReadable()
is External Storage Readable
String state = Environment.getExternalStorageState();
return Environment.MEDIA_MOUNTED.equals(state)
        || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state);
booleanisExternalStorageWritable()
is External Storage Writable
String state = Environment.getExternalStorageState();
return Environment.MEDIA_MOUNTED.equals(state);