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

booleanhasExternalStorage()
has External Storage
Boolean externalStorage = Environment.getExternalStorageState()
        .equals(android.os.Environment.MEDIA_MOUNTED);
return externalStorage;
booleanisExtStorageReadable()
is Ext Storage Readable
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)
        || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
    return true;
return false;
booleanisExtStorageWritable()
is Ext Storage Writable
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
    return true;
return false;
booleanisExternalStorageWritable()
is External Storage Writable
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
    return true;
return false;
booleanisExternalStoragePresent()
private static boolean isExternalStoragePresent()

this method can used to check that external storage(Sd card on device ) is available on device or not
boolean mExternalStorageAvailable = false;
boolean mExternalStorageWriteable = false;
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
    mExternalStorageAvailable = mExternalStorageWriteable = true;
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
    mExternalStorageAvailable = true;
    mExternalStorageWriteable = false;
...
FilegetAlbumStorageDirectory(String albumName)
get Album Storage Directory
File file = new File(
        Environment
                .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
        albumName);
if (!file.mkdirs()) {
    Log.e("", "Directory not created");
return file;
...
FilegetExtStoragePubDir(String dirName, String dirType)
get Ext Storage Pub Dir
File path = new File(
        Environment.getExternalStoragePublicDirectory(dirType),
        dirName);
if (!path.mkdirs()) {
    Log.e("ExtStorageUtils", "Directory not created");
return path;
longgetAvailableStorageSize(File dir)
get Available Storage Size
long size = -1;
if (dir != null && dir.exists() && dir.isDirectory()) {
    try {
        StatFs stat = new StatFs(dir.getPath());
        size = (long) stat.getBlockSize()
                * stat.getAvailableBlocks();
    } catch (Exception e) {
        e.printStackTrace();
...
FilegetDatafilesStorageDirectory(Context context)
get Datafiles Storage Directory
return context.getExternalFilesDir(null);