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

private static Uri getUri() {
    String state = Environment.getExternalStorageState();
    if (!state.equalsIgnoreCase(Environment.MEDIA_MOUNTED))
        return MediaStore.Images.Media.INTERNAL_CONTENT_URI;

    return MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
}

From source file:Main.java

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

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

public static String getSdCacheDir(Context context) {
    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()) {
            result = autonaviDir.mkdir();
        }//w  ww .j  a v a2 s.  co m
        java.io.File minimapDir = new java.io.File(autonaviDir, "offlineMap");
        if (!minimapDir.exists()) {
            result = minimapDir.mkdir();
        }
        return minimapDir.toString() + "/";
    } else {
        return "";
    }
}

From source file:Main.java

public static String getSDPath() {
    File sdDir = null;//from  ww w .  j  a  v  a2 s.  co m
    boolean sdCardExist = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
    if (sdCardExist) {
        sdDir = Environment.getExternalStorageDirectory(); // get root path
        return sdDir.toString();
    }
    return null;
}

From source file:Main.java

public static String getSDPath() {
    File sdDir = null;/*from   ww  w  .ja  va 2  s  . c o m*/
    boolean sdCardExist = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
    if (sdCardExist) {
        sdDir = Environment.getExternalStorageDirectory();
    }
    String dir = sdDir.toString();
    return dir;
}

From source file:Main.java

public static String getRootByApi() {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        File file = Environment.getExternalStorageDirectory();
        if (file == null)
            return null;
        String path = file.getAbsolutePath();
        if (isValidRoot(path))
            return path;
    }/*  w ww . jav a 2  s .  co m*/
    return null;
}

From source file:Main.java

public static boolean CheckExternStorage(Context context) {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        return true;
    } else {//from ww w  . j  a  va  2  s.  c  o m
        return false;
    }
}

From source file:Main.java

public static String getSDPath() {
    File SDdir = null;/*from  w  w w  . ja  v  a2s . c o  m*/
    boolean sdCardExist = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
    if (sdCardExist) {
        SDdir = Environment.getExternalStorageDirectory();
    }
    if (SDdir != null) {
        return SDdir.toString();
    } else {
        return null;
    }
}

From source file:Main.java

public static File getTempImage() throws IOException {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        File tempFile = new File(Environment.getExternalStorageDirectory(), "temp.jpg");
        tempFile.createNewFile();// w w w .  ja  va  2s .com
        return tempFile;
    }
    throw new IOException("cannot find any sdcard.");
}