Example usage for android.os Environment getExternalStorageState

List of usage examples for android.os Environment getExternalStorageState

Introduction

In this page you can find the example usage for android.os Environment getExternalStorageState.

Prototype

public static String getExternalStorageState() 

Source Link

Document

Returns the current state of the primary shared/external storage media.

Usage

From source file:Main.java

/**
 * @return/*www .  ja  va  2 s.c  om*/
 */
private static boolean hasSDCard() {
    return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
}

From source file:Main.java

public static boolean isExternalStorageAvailableforWriting() {

    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        // We can read and write the media
        return true;
    } else {/*from w w  w  .  ja  va  2  s  .  co m*/
        return false;
    }

}

From source file:Main.java

public static boolean isExternalStorageAvailableforReading() {

    String state = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state) || Environment.MEDIA_MOUNTED.equals(state)) {
        return true;
    } else {/*  w w w. j a va 2 s  .c  om*/
        return false;
    }

}

From source file:Main.java

public static boolean isExternalStorageAvailable() {
    String state = Environment.getExternalStorageState();
    if (!Environment.MEDIA_MOUNTED.equals(state)) {
        Log.d(TAG, "The external storage is not available.");
        return false;
    }//from  w ww  . ja v a2s. c  om
    return true;
}

From source file:Main.java

public static boolean isExternalStorageAvailable() {
    return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            || !isExternalStorageRemovable();
}

From source file:Main.java

private static File getAlbumDir() {
    File storageDir = null;/*from   w  ww .j  a v a 2 s .  co m*/
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        storageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
                "Telepathy");
        if (!storageDir.mkdirs()) {
            if (!storageDir.exists()) {
                Log.d("android_utilities", "failed to create directory");
                return null;
            }
        }
    } else {
        Log.d("android_utilities", "External storage is not mounted READ/WRITE.");
    }
    return storageDir;
}

From source file:Main.java

public static boolean hasSDCard() {
    String status = Environment.getExternalStorageState();
    if (!status.equals(Environment.MEDIA_MOUNTED)) {
        return false;
    }//from  w w w .  j a  v  a2  s.  c  om
    return true;
}

From source file:Main.java

public static boolean isExternalStoragePresent() {
    return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
}

From source file:Main.java

public static String getCacheDir() {
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            || !Environment.isExternalStorageRemovable()) {
        File cacheFile = mAppContext.getExternalCacheDir();
        if (null != cacheFile) {
            return cacheFile.getPath();
        }//from  w w w .ja va  2  s .c o  m
    }
    return mAppContext.getCacheDir().getPath();
}

From source file:Main.java

public static File getCacheDirectory(Context context) {
    if (context == null)
        return null;

    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        return context.getExternalCacheDir();
    }/*  www.  j a  va  2s .co  m*/

    return context.getCacheDir();
}