Example usage for android.os Environment MEDIA_MOUNTED

List of usage examples for android.os Environment MEDIA_MOUNTED

Introduction

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

Prototype

String MEDIA_MOUNTED

To view the source code for android.os Environment MEDIA_MOUNTED.

Click Source Link

Document

Storage state if the media is present and mounted at its mount point with read/write access.

Usage

From source file:Main.java

/**
 * Check external exist or not.//  w  w  w  .jav  a 2s .c o m
 *
 * @return
 */
public static boolean hasExternalStorage() {
    return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
}

From source file:Main.java

/**
 * @return true if the data path is currently available. However, it can vanish at any time so
 * normally you should just try to use it and rely on the exceptions.
 *///from w ww.  j  a  v a 2s.  c o  m
public static boolean isDataPathAvailable() {
    return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
}

From source file:Main.java

/**
 * Returns application files directory. Files directory will be created on SD card
 * <i>("/Android/data/[app_package_name]/files")</i> if card is mounted. Else - Android defines files directory on
 * device's file system.//from  w w w .  j a  v  a 2 s .c o m
 * 
 * @param context Application context
 * @return Files {@link File directory}
 */
public static File getFilesDirectory(Context context) {
    File appFilesDir = null;
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        appFilesDir = getExternalFilesDir(context);
    }
    if (appFilesDir == null) {
        appFilesDir = context.getFilesDir();
    }
    return appFilesDir;
}

From source file:Main.java

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

From source file:Main.java

public static File createSDDir(String dirName) throws IOException {
    File dir = new File(SDPATH + dirName);
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {

        System.out.println("createSDDir:" + dir.getAbsolutePath());
        System.out.println("createSDDir:" + dir.mkdir());
    }//from w  ww . j  a v a  2 s .  c  om
    return dir;
}

From source file:Main.java

/**
 * if sdcard available return true ,else return false
 * *//* w  w w . j a v  a2  s  . co m*/
public static boolean isSdcardAvailable() {
    String sdcardStatus = Environment.getExternalStorageState();
    return sdcardStatus.equals(Environment.MEDIA_MOUNTED) ? true : false;
}

From source file:Main.java

/**
 * Checks if the external media (SD Card) is writable
 *
 * @return boolean True if Writable/*w  ww  .j a  v  a2 s.c  o  m*/
 */
public static boolean isSdWritable() {

    boolean mExternalStorageAvailable = false;
    try {
        String state = Environment.getExternalStorageState();

        if (Environment.MEDIA_MOUNTED.equals(state)) {
            // We can read and write the media
            mExternalStorageAvailable = true;
            Log.i(TAG, mTAG + ": External storage card is readable.");
        } else {
            mExternalStorageAvailable = false;
        }
    } catch (Exception ex) {
        Log.e(TAG, mTAG + ":isSdWritable - " + ex.getMessage());
    }
    return mExternalStorageAvailable;
}

From source file:Main.java

public static boolean hasSdCard() {
    boolean sResult = false;

    String stateString = null;// ww  w  .j a  va 2 s .  com
    try {
        Class c = Class.forName("android.os.SystemProperties");
        Method m[] = c.getDeclaredMethods();

        try {
            try {
                stateString = (String) m[1].invoke(null, "EXTERNAL_STORAGE_STATE", "unmounted");
            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if (stateString != null) {
        if (stateString.equals(Environment.MEDIA_MOUNTED)) {
            sResult = true;
        }
    }
    return sResult;
}

From source file:Main.java

/**
 * Returns specified application cache directory. Cache directory will be created on SD card by defined path if card
 * is mounted. Else - Android defines cache directory on device's file system.
 * //  w w  w .  j av a  2 s .  c  o m
 * @param context Application context
 * @param cacheDir Cache directory path (e.g.: "AppCacheDir", "AppDir/cache/images")
 * @return Cache {@link File directory}
 */
public static File getOwnCacheDirectory(Context context, String cacheDir) {
    File appCacheDir = null;
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        appCacheDir = new File(Environment.getExternalStorageDirectory(), cacheDir);
    }
    if (appCacheDir == null || (!appCacheDir.exists() && !appCacheDir.mkdirs())) {
        appCacheDir = context.getCacheDir();
    }
    return appCacheDir;
}

From source file:Main.java

public static File getSDPath(Context context) {
    File sdDir = context.getCacheDir();
    boolean sdCardExist = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
    if (sdCardExist) {
        sdDir = Environment.getExternalStorageDirectory();
    }/*from   ww  w.  j ava  2  s .c  o m*/
    return sdDir;
}