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.appassit.common.Utils.java

/**
 * Check whether the SD card is readable
 *///www. ja v  a2s  .  c  o m
public static boolean isSdcardReadable() {
    final String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state) || Environment.MEDIA_MOUNTED.equals(state)) {
        return true;
    }
    return false;
}

From source file:org.geek.utils.ApplicationUtils.java

/**
 * Check if the SD card is available. Display an alert if not.
 * @param context The current context./*from   ww w.  j  a v  a  2  s  .com*/
 * @param showMessage If true, will display a message for the user.
 * @return True if the SD card is available, false otherwise.
 */
public static boolean checkCardState(Context context, boolean showMessage) {
    // Check to see if we have an SDCard
    String status = Environment.getExternalStorageState();
    if (!status.equals(Environment.MEDIA_MOUNTED)) {

        int messageId;

        // Check to see if the SDCard is busy, same as the music app
        if (status.equals(Environment.MEDIA_SHARED)) {
            messageId = R.string.Commons_SDCardErrorSDUnavailable;
        } else {
            messageId = R.string.Commons_SDCardErrorNoSDMsg;
        }

        if (showMessage) {
            ApplicationUtils.showErrorDialog(context, R.string.Commons_SDCardErrorTitle, messageId);
        }

        return false;
    }

    return true;
}

From source file:com.appassit.common.Utils.java

/**
 * Check whether the SD card is writable
 *///from www.  j  a v  a 2  s . c o m
public static boolean isSdcardWritable() {
    final String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        return true;
    }
    return false;
}

From source file:de.unwesen.web.DownloadCache.java

private String getCacheDir() {
    Context ctx = mContext.get();
    if (null == ctx) {
        return null;
    }//from   w w w.j  a  v a  2 s.  c  om

    File cache_dir = ctx.getCacheDir();
    String root = cache_dir.getPath();

    if (mTunables.useExternalStorage()
            && Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        cache_dir = Environment.getExternalStorageDirectory();
        root = cache_dir.getPath() + File.separator + "data" + File.separator + ctx.getPackageName();
    }

    // Log.d(LTAG, "Cache dir: " + root + File.separator + mCachePrefix + File.separator);
    return root + File.separator + mCachePrefix + File.separator;
}

From source file:com.bamobile.fdtks.util.Tools.java

public static boolean isSdReadable() {
    boolean mExternalStorageAvailable = false;
    String state = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(state)) {
        // We can read and write the media
        mExternalStorageAvailable = true;
        Log.i("isSdReadable", "External storage card is readable.");
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        // We can only read the media
        Log.i("isSdReadable", "External storage card is readable.");
        mExternalStorageAvailable = true;
    } else {//w w w.  java  2  s .  co  m
        // Something else is wrong. It may be one of many other
        // states, but all we need to know is we can neither read nor write
        mExternalStorageAvailable = false;
    }

    return mExternalStorageAvailable;
}

From source file:com.commontime.cordova.audio.AudioPlayer.java

/**
 * Save temporary recorded file to specified name
 *
 * @param file/*from ww w.java 2 s.  co m*/
 */
public void moveFile(String file) {
    /* this is a hack to save the file as the specified name */
    File f = new File(this.tempFile);

    if (!file.startsWith("/")) {
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            file = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + file;
        } else {
            file = "/data/data/" + handler.cordova.getActivity().getPackageName() + "/cache/" + file;
        }
    }

    String logMsg = "renaming " + this.tempFile + " to " + file;
    Log.d(LOG_TAG, logMsg);

    if (f.exists()) {
        if (!f.renameTo(new File(file)))
            Log.e(LOG_TAG, "FAILED " + logMsg);
    }
}

From source file:it.iziozi.iziozi.gui.IOBoardFragment.java

public boolean isExternalStorageWritable() {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        return true;
    }/*from  w  w  w .  jav a 2 s  . co m*/
    return false;
}

From source file:com.wikonos.fingerprint.activities.MainActivity.java

@Override
public void onClickFeature(View v) {
    /**/*from  www.  ja va 2  s  . c  om*/
     * Checks SD Card mounted
     */
    if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        standardAlertDialog(getString(R.string.msg_alert), getString(R.string.msg_sd_card_disabled), null);
        return;
    }
    switch (v.getId()) {
    // select states
    case R.id.bSelectState:
        showDialog(DIALOG_ID_STATES);
        break;
    // review past scan log
    case R.id.bReview:
        //showDialog(DIALOG_ID_REVIEW);
        getDialogReviewLogs().show();
        break;
    default:
        super.onClickFeature(v);
    }
}

From source file:cn.sharesdk.analysis.util.PreferencesHelper.java

public void saveInfoToFile(JSONObject existJSON) {
    try {//from   ww w .ja  v  a 2 s . c o m
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) && DeviceHelper
                .getInstance(context).checkPermissions("android.permission.WRITE_EXTERNAL_STORAGE")) {
            // Does a cached file exist
            File cacheRoot = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), packageName);
            if (!cacheRoot.exists()) {
                cacheRoot.mkdirs();
                Ln.i("cacheRoot path", "no path");
            }

            File cacheFile = new File(cacheRoot, "mobclick_agent_json_cached_" + packageName);
            if (!cacheFile.exists()) {
                cacheFile.createNewFile();
                Ln.i("cacheFile path", "no path createNewFile");
            }

            // save json data to the cached file
            FileOutputStream fileOutputStream = new FileOutputStream(cacheFile, false);
            fileOutputStream.write(existJSON.toString().getBytes());
            fileOutputStream.flush();
            fileOutputStream.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

}