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

/**
 * clean external cache(/mnt/sdcard/android/data/com.xxx.xxx/cache)
 *
 * @param context/*from w ww .j  av a  2 s . c o  m*/
 */
public static void cleanExternalCache(Context context) {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        deleteFilesInDirectory(context.getExternalCacheDir());
    }
}

From source file:Main.java

/**
 * @return {@code true} if external storage is available and writable. {@code false} otherwise.
 *///from   w  w w .j a v  a2  s.c o m
public static boolean isExternalStorageAvailable() {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        return true;
    }
    return false;
}

From source file:Main.java

public static File getCacheFile(@NonNull Context context, @NonNull String fileName) {
    File savedir = null;//from w  w w  . jav  a 2s  . co m
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        savedir = new File(context.getExternalCacheDir(), fileName);
    }

    if (savedir == null) {
        savedir = new File(context.getCacheDir(), fileName);
    }

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

From source file:Main.java

public static boolean isSDCardPresent(final Activity a) {
    String storageState = Environment.getExternalStorageState();
    return storageState.equals(Environment.MEDIA_MOUNTED);
}

From source file:Main.java

public static String assetToSd(Context ctx, String inFileName, String outFileName) {

    try {//from   ww  w  . java 2 s.  co  m
        InputStream is = ctx.getAssets().open(inFileName);
        if (is == null) {
            return null;
        }

        if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
            String sd = Environment.getExternalStorageDirectory().getAbsolutePath();
            String path = sd + "/uexTencent/";
            File filePath = new File(path);
            if (!filePath.exists()) {
                filePath.mkdirs();
            }
            String fileName = path + outFileName;
            FileOutputStream fos = new FileOutputStream(fileName);

            byte[] buf = new byte[1024];
            int len = 0;
            int total = 0;
            while ((len = is.read(buf)) != -1) {
                fos.write(buf, 0, len);
                total++;
            }
            is.close();
            fos.close();
            fileSize = total;
            return fileName;
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

/**
 * @param context/*from ww w.  j a v a2 s . com*/
 * @param dirName Only the folder name, not contain full path.
 * @return app_cache_path/dirName
 */
public static String getDiskCacheDir(Context context, String dirName) {
    final String cachePath = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            ? context.getExternalCacheDir().getPath()
            : context.getCacheDir().getPath();

    return cachePath + File.separator + dirName;
}

From source file:Main.java

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

From source file:Main.java

/**
 * @param context/* www.  j  av a 2  s  . c  o  m*/
 * @param dirName Only the folder name, not full path.
 * @return app_cache_path/dirName
 */
public static String getDiskCacheDir(Context context, String dirName) {
    String cachePath = null;
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        File externalCacheDir = context.getExternalCacheDir();
        if (externalCacheDir != null) {
            cachePath = externalCacheDir.getPath();
        }
    }
    if (cachePath == null) {
        File cacheDir = context.getCacheDir();
        if (cacheDir != null && cacheDir.exists()) {
            cachePath = cacheDir.getPath();
        }
    }

    return cachePath + File.separator + dirName;
}

From source file:Main.java

public static String getOutputMediaFolderPath() {
    // To be safe, you should check that the SDCard is mounted
    // using Environment.getExternalStorageState() before doing this.
    if (!Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_MOUNTED)) {
        return null;
    }/* w ww  . j av a  2 s  .  co m*/

    File mediaStorageDir = new File(
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "HDMIRxDemo");
    // This location works best if you want the created images to be shared
    // between applications and persist after your app has been uninstalled.

    // Create the storage directory if it does not exist
    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {
            Log.d("CameraSample", "failed to create directory");
            return null;
        }
    }
    // return path string of the folder
    return mediaStorageDir.getAbsolutePath();
}

From source file:Main.java

public static boolean isEnoughMemory(int fileSize) {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        int freeSpace = getFreeMemory(Environment.getExternalStorageDirectory().getAbsolutePath());
        if (freeSpace > fileSize) {
            return true;
        } else//from w  w  w  .ja v  a  2s. c om
            return false;

    } else
        return false;
}