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:com.momock.util.Logger.java

public static void open(Context context, String logfilename, int level) {
    if (!enabled)
        return;/*from w  w w  .  j av a  2 s. com*/
    logFileName = logfilename;
    if (logStream == null) {
        logStream = System.out;
        File logDir = null;
        try {
            if (getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
                logDir = Environment.getExternalStorageDirectory();
            } else if (context != null) {
                logDir = context.getCacheDir();
            }
            if (logDir != null) {
                android.util.Log.d("Logger", logDir.getAbsolutePath());
                logStream = new PrintStream(new FileOutputStream(new File(logDir, logFileName), false));
            }
        } catch (IOException e) {
            android.util.Log.e("Logger", "Fails to create log file!", e);
        }
    }
    logLevel = level;

    logStream.println("========== Logger Begin ==========");
    logStream.flush();
}

From source file:model.Document.java

/**
 * @return the validity in memory of this Document. A document is valid in
 *         memory during a week//  ww  w . j av a  2  s . c o  m
 */
public boolean isOnMemory() {
    if (mLoadedDate.plusWeeks(1).isAfterNow()) {
        // Exits the function if the storage is not writable!
        if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            Log.d("ClaroClient", "Missing SDCard");
            return false;
        }

        File root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);

        File file = new File(root.getAbsolutePath(), getTitle() + "." + getExtension());
        return file.exists() && file.canRead();
    }
    return false;
}

From source file:com.twapime.app.util.AsyncImageLoader.java

/**
 * /*from   w w  w .j a va2  s  .co m*/
 */
private void loadCacheDir() {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        File sdDir = Environment.getExternalStorageDirectory();
        cacheDir = new File(sdDir.getAbsolutePath() + "/TwAPIme/cache");
        //
        if (!cacheDir.exists()) {
            cacheDir.mkdirs();
        }
    } else {
        cacheDir = context.getCacheDir();
    }
}

From source file:com.tcl.lzhang1.mymusic.AppException.java

/**
 * Save log./*from  w ww. jav a  2  s  .  com*/
 * 
 * @param ex the ex
 */
private void saveLog(Throwable ex) {
    String errorlog = "errorlog.txt";
    String savePath = "";
    String logFilePath = "";
    FileWriter fw = null;
    PrintWriter pw = null;
    try {

        String storageState = Environment.getExternalStorageState();
        if (storageState.equals(Environment.MEDIA_MOUNTED)) {
            savePath = Environment.getExternalStorageDirectory().getAbsolutePath()
                    + "/Android/data/com.tcl.lzhang1.mymusic/Log/";
            File file = new File(savePath);
            if (!file.exists()) {
                file.mkdirs();
            }
            logFilePath = savePath + errorlog;
        }

        if (logFilePath == "") {
            return;
        }
        File logFile = new File(logFilePath);
        if (!logFile.exists()) {
            logFile.createNewFile();
        }
        fw = new FileWriter(logFile, true);
        pw = new PrintWriter(fw);
        pw.println("--------------------" + (new Date().toLocaleString())
                + "-------------------setDefaultUncaughtExceptionHandler--");
        ex.printStackTrace(pw);
        pw.close();
        fw.close();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (pw != null) {
            pw.close();
        }
        if (fw != null) {
            try {
                fw.close();
            } catch (IOException e) {
            }
        }
    }

}

From source file:com.todotxt.todotxttouch.util.Util.java

public static boolean isDeviceWritable() {
    String sdState = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(sdState)) {
        return true;
    } else {//from   w ww  . j a  v a  2s  .c o m
        return false;
    }
}

From source file:com.todotxt.todotxttouch.util.Util.java

public static boolean isDeviceReadable() {
    String sdState = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(sdState) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(sdState)) {
        return true;
    } else {//from  w  w w  . jav  a2  s.  c om
        return false;
    }
}

From source file:com.androidzeitgeist.dashwatch.common.IOUtil.java

@TargetApi(Build.VERSION_CODES.KITKAT)
public static File getBestAvailableCacheRoot(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // In KitKat we can query multiple devices.
        // TODO: optimize for stability instead of picking first one
        File[] roots = context.getExternalCacheDirs();
        if (roots != null) {
            for (File root : roots) {
                if (root == null) {
                    continue;
                }/*  w w  w .j a  v a  2 s.  co  m*/

                if (Environment.MEDIA_MOUNTED.equals(Environment.getStorageState(root))) {
                    return root;
                }
            }
        }

    } else if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        // Pre-KitKat, only one external storage device was addressable
        return context.getExternalCacheDir();
    }

    // Worst case, resort to internal storage
    return context.getCacheDir();
}

From source file:com.akop.bach.ImageCache.java

public File getCacheDirectory() {
    File cacheDir = mCacheDir;/*from   w w  w . j  a va 2 s  . c om*/

    if (mSdCacheDir != null && Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        if (mSdCacheDir.exists() || mSdCacheDir.mkdirs())
            cacheDir = mSdCacheDir;
    }

    return cacheDir;
}

From source file:com.phonegap.customcamera.NativeCameraLauncher.java

private String getTempDirectoryPath(Context ctx) {
    File cache = null;//w  ww .j  ava2 s  .  co  m

    // SD Card Mounted
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        cache = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/"
                + ctx.getPackageName() + "/cache/");
    }
    // Use internal storage
    else {
        cache = ctx.getCacheDir();
    }

    // Create the cache directory if it doesn't exist
    if (!cache.exists()) {
        cache.mkdirs();
    }

    return cache.getAbsolutePath();
}

From source file:com.ichi2.anki.AnkiDroidApp.java

public static boolean isSdCardMounted() {
    return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
}