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

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   www  . j  av  a2  s  . co  m
        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  ww  w. j  a va  2 s. c  o m
    return true;
}

From source file:Main.java

/**
 * Checks if {@link Environment}.MEDIA_MOUNTED is returned by
 * {@code getExternalStorageState()} and therefore external storage is read-
 * and writeable.//from   w  w w .  j  a va2s . c o  m
 */
public static boolean isExtStorageAvailable() {
    return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
}

From source file:Main.java

private static File getAlbumDir() {
    File storageDir = null;//from  ww  w.j  a v a2 s. c  om
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        storageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
                "Telegram");
        if (!storageDir.mkdirs()) {
            if (!storageDir.exists()) {
                //                    FileLog.d("tmessages", "failed to create directory");
                return null;
            }
        }
    } else {
        //            FileLog.d("tmessages", "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  va2  s. c o m
    return true;
}

From source file:Main.java

/**Check whether the sdcard is available
 * @return True if the sdcard is available, otherwise return false
 *///from  w  w  w .  j  a  v  a 2 s  .  c o m
public static boolean sdcardIsAvailable() {
    return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
}

From source file:Main.java

/**
 * obtain /sdcard/Android/data/[packagename]/files
 *///from   ww w .j  av  a 2 s.c  o m
public static String getSdFilesDir(Context context) {
    //TODO: check permission?
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        File filesDir = context.getExternalFilesDir(null);
        if (filesDir != null) {
            return filesDir.getAbsolutePath();
        } else {
            return "";
        }
    } else {
        return "";
    }
}

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 {//  ww  w  .java2s.co  m
        return false;
    }

}

From source file:Main.java

public static String getFile(@NonNull Context context) {
    File savedir = null;//from www  .  j  a  v  a 2s. com
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        savedir = context.getExternalFilesDir(null);
    }

    if (savedir == null) {
        savedir = context.getFilesDir();
    }

    if (!savedir.exists()) {
        savedir.mkdirs();
    }
    return savedir.getAbsolutePath();
}

From source file:Main.java

/**
 * Returns true if the android external storage is writeable.
 */// w  ww .  j a  v a2s. c o m
public static boolean isExternalStorageWriteable() {
    return (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()));
}