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

public static boolean hasExternalStorage() {
    boolean externalStorage = Environment.getExternalStorageState()
            .equals(android.os.Environment.MEDIA_MOUNTED);
    return externalStorage;
}

From source file:Main.java

public static boolean checkState() {
    boolean mExternalStorageAvailable = false;
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        mExternalStorageAvailable = true;
    }//from  w  ww  .ja v a 2 s  . c o m
    return mExternalStorageAvailable;
}

From source file:Main.java

public static File createFile(Context context) {
    File file;/*from  ww  w.j av a  2 s .com*/
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        String timeStamp = String.valueOf(new Date().getTime());
        file = new File(Environment.getExternalStorageDirectory() + File.separator + timeStamp + ".jpg");
    } else {
        File cacheDir = context.getCacheDir();
        String timeStamp = String.valueOf(new Date().getTime());
        file = new File(cacheDir, timeStamp + ".jpg");
    }
    return file;
}

From source file:Main.java

static public boolean externalStorageMounted() {
    String state = Environment.getExternalStorageState();
    return Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state);
}

From source file:Main.java

public static boolean sdCardIsAvailable() {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        File sd = new File(Environment.getExternalStorageDirectory().getPath());
        return sd.canWrite();
    } else/*from  ww w  . jav a  2s  . c om*/
        return false;
}

From source file:Main.java

public static boolean isExitsSdcard() {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
        return true;
    else//from w ww  . j  a  v  a  2  s  . co  m
        return false;
}

From source file:Main.java

public static boolean hasSDCardMounted() {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        return true;
    }/* w  w  w . j  a  v a  2  s.  c  o  m*/
    try {
        if ((Build.MANUFACTURER).equalsIgnoreCase("HTC") && (Build.DEVICE).equalsIgnoreCase("inc")) {
            return true;
        }
    } catch (Exception pEx) {
        return false;
    }
    return false;
}

From source file:Main.java

public static boolean isExternalStorageReadable() {
    String state = Environment.getExternalStorageState();
    return Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state);
}

From source file:Main.java

@SuppressLint("SdCardPath")
public static File getCacheDirectory(Context context, boolean preferExternal, String dirName) {
    File appCacheDir = null;/*from   w w  w. j a va  2  s  .co  m*/
    if (preferExternal && MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            && hasExternalStoragePermission(context)) {
        appCacheDir = getExternalCacheDir(context, dirName);
    }
    if (appCacheDir == null) {
        appCacheDir = context.getCacheDir();
    }
    if (appCacheDir == null) {
        String cacheDirPath = "/data/data/" + context.getPackageName() + "/cache/";
        Log.w("Can't define system cache directory! '%s' will be used.", cacheDirPath);
        appCacheDir = new File(cacheDirPath);
    }
    return appCacheDir;
}

From source file:Main.java

private static boolean isStorageReady() {
    String cardstatus = Environment.getExternalStorageState();
    if (cardstatus.equals(Environment.MEDIA_REMOVED) || cardstatus.equals(Environment.MEDIA_UNMOUNTED)
            || cardstatus.equals(Environment.MEDIA_UNMOUNTABLE)
            || cardstatus.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
        return false;
    } else {/*  www  .  j a  v  a  2 s  . c o m*/
        if (cardstatus.equals(Environment.MEDIA_MOUNTED)) {
            return true;
        } else {
            return false;
        }
    }
}