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 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 getFileRoot(Context context) {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        File external = context.getExternalFilesDir(null);
        if (external != null) {
            return external.getAbsolutePath();
        }/*from   w ww .j a  v a 2s.  c o  m*/
    }
    return context.getFilesDir().getAbsolutePath();
}

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 {/*w  ww  . j  a  va2 s. c o m*/
        return false;
    }
}

From source file:Main.java

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

From source file:Main.java

private static String getFileRoot(Context context) {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        File external = context.getExternalFilesDir(null);
        if (external != null) {
            return external.getAbsolutePath();
        }//  w w w. j a v  a2  s  . c  o m
    }

    return context.getFilesDir().getAbsolutePath();
}

From source file:Main.java

public static File getWritableFileDir(Context context) {
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        File file = context.getExternalFilesDir(null);
        if (file == null) {
            file = context.getFilesDir();
        }/*from  www . j av a  2s . c  o m*/
        return file;
    } else {
        return context.getFilesDir();
    }
}

From source file:Main.java

public static void creatFile(String fileName) {
    if (sdState.equals(Environment.MEDIA_MOUNTED)) {
        File file = new File(
                Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + fileName);
        if (!file.exists()) {
            file.mkdir();/*from  ww  w  .ja v a2 s .c  o m*/
        }
    }
}

From source file:Main.java

public static String getSavePath() {
    String savePath = null;// w  w w .ja  v  a2  s. co m
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        savePath = Environment.getExternalStorageDirectory().getAbsolutePath();
    } else {
        File[] files = new File("/mnt/").listFiles();
        if (files.length > 0) {
            String filePath = null;
            for (int p = 0; p < files.length; p++) {
                if (files[p].isDirectory()) {
                    if (files[p].getPath().indexOf("sdcard") >= 0) {
                        StatFs st = new StatFs(files[p].getPath());
                        int blocksize = st.getBlockSize();
                        int blockcount = st.getBlockCount();
                        if ((blocksize * blockcount) > 0) {
                            filePath = files[p].getPath();
                        }
                    }

                }
            }
            if (filePath != null) {
                savePath = filePath;
            } else {
                savePath = null;
            }
        }
    }
    return savePath;
}

From source file:Main.java

public static void setCacheRoot(Context context) {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        mCacheRoot = Environment.getExternalStorageDirectory().getPath() + "/";
    } else {/*from w ww .j  a  va  2  s.co  m*/
        mCacheRoot = context.getCacheDir().getPath() + "/";
    }
}

From source file:Main.java

public static boolean deleteFile(File file) {
    if (sdState.equals(Environment.MEDIA_MOUNTED)) {
        if (file.exists()) {
            if (file.isFile()) {
                return file.delete();
            }//from   w  w  w  . j a  v a  2  s.co m
        } else {
            return true; // file not exist
        }
    }
    return false;
}