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.polyvi.xface.util.XFileUtils.java

/**
 * ?sdcard//from  w  ww. j  a va  2 s  .c  om
 *
 * @return sdcard??sdcard?null
 */
public static String getSdcardPath() {
    String path = null;
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        path = Environment.getExternalStorageDirectory().getAbsolutePath();
    } else {
        path = XExternalStorageScanner.getExternalStoragePath();
    }
    if (null == path) {
        XLog.w(CLASS_NAME, "No External Storage");
        return null;
    }
    File filePath = null;
    try {
        filePath = new File(path).getCanonicalFile();
    } catch (IOException e) {
        XLog.e(CLASS_NAME, e.getMessage());
        e.printStackTrace();
        return null;
    }
    return filePath.getAbsolutePath();
}

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

/**
 * Constructor.//from w w w.  ja v  a  2s. co m
 *
 * @param handler           The audio handler object
 * @param id                The id of this audio player
 */
public AudioPlayer(AudioHandler handler, String id, String file) {
    this.handler = handler;
    this.id = id;
    this.audioFile = file;
    this.recorder = new MediaRecorder();

    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        this.tempFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/tmprecording.m4a";
    } else {
        this.tempFile = "/data/data/" + handler.cordova.getActivity().getPackageName()
                + "/cache/tmprecording.m4a";
    }

}

From source file:ch.ethz.dcg.jukefox.commons.utils.AndroidUtils.java

public static boolean isSdCardOk() {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        return true;
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        Log.w(TAG, "Access to sd-card is read only");
        return false;
    } else {//from ww w.jav  a  2  s  . c o  m
        return false;
    }

}

From source file:de.fmaul.android.cmis.utils.StorageUtils.java

public static File getStorageFile(Application app, String repoId, String storageType, String itemId,
        String filename) throws StorageException {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        StringBuilder builder = new StringBuilder();
        builder.append(Environment.getExternalStorageDirectory());
        builder.append("/");
        builder.append("Android");
        builder.append("/");
        builder.append("data");
        builder.append("/");
        builder.append(app.getPackageName());
        builder.append("/");
        if (storageType != null) {
            builder.append("/");
            builder.append(storageType);
        }/*from  w ww  .  ja  v a  2s.  c o  m*/
        if (repoId != null) {
            builder.append("/");
            builder.append(repoId);
        }
        if (itemId != null) {
            builder.append("/");
            builder.append(itemId.replaceAll(":", "_"));
        }
        if (filename != null) {
            builder.append("/");
            builder.append(filename);
        }
        return new File(builder.toString());
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        throw new StorageException("Storage in Read Only Mode");
    } else {
        throw new StorageException("Storage is unavailable");
    }
}

From source file:de.petermoesenthin.alarming.util.FileUtil.java

/**
 * Checks if the external storage is readable
 *
 * @return//w w  w .  j a v  a  2  s  . c o m
 */
public static boolean isExternalStorageReadable() {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        return true;
    }
    return false;
}

From source file:com.lillicoder.newsblurry.util.FileLogger.java

/**
 * Determines if the external storage media is available for writing.
 * @return <code>true</code> if external storage is available for writing,
 *          <code>false</code> otherwise.
 *///  ww  w  . j a  v  a 2  s  . c o m
private boolean isExternalStorageAvailable() {
    String externalMediaState = Environment.getExternalStorageState();
    return Environment.MEDIA_MOUNTED.equals(externalMediaState);
}

From source file:com.urremote.classifier.common.ExceptionHandler.java

private void writeToFile(String stacktrace, String filename) {
    try {/*from w w w.ja  va2 s.co  m*/
        File outputFile = new File(Constants.PATH_SD_CARD_APP_LOC + File.separator + filename);

        if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            Log.e(Constants.TAG, "Unable to write stacktrace to file. External media not mounted!");
            return;
        }

        Log.v(Constants.TAG, "Output Trace File:" + outputFile);
        if (!outputFile.getParentFile().exists()) {
            if (!outputFile.getParentFile().mkdirs()) {
                Log.e(Constants.TAG, "Unable to create log file directory:\n" + outputFile.getParentFile()
                        + "\nCaused when writing stack to file:\n" + stacktrace);
            }
        }
        if (!outputFile.exists()) {
            if (!outputFile.createNewFile()) {
                Log.e(Constants.TAG, "Unable to create log file:\n" + outputFile.getParentFile()
                        + "\nCaused when writing stack to file:\n" + stacktrace);
            }
        }
        BufferedWriter bos = new BufferedWriter(new FileWriter(outputFile));
        bos.write(stacktrace);
        bos.flush();
        bos.close();
        Log.e(Constants.TAG, stacktrace);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.binomed.showtime.android.util.images.ImageDownloader.java

private InputStream writeFile(String url, InputStream inputStream) {
    InputStream returnInputStream = inputStream;
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        try {/*from ww w  .j a  v  a  2  s.  c om*/
            File root = Environment.getExternalStorageDirectory();
            File imageFile = new File(root,
                    new StringBuilder(CineShowtimeCst.FOLDER_POSTER).append(getFileName(url)).toString());
            if (!imageFile.getParentFile().exists()) {
                imageFile.mkdirs();
            }
            if (!imageFile.exists()) {
                imageFile.createNewFile();
                FileOutputStream fileOutPut = new FileOutputStream(imageFile);
                byte[] tempon = new byte[10240];

                while (true) {
                    int nRead = inputStream.read(tempon, 0, tempon.length);
                    if (nRead <= 0) {
                        break;
                    }
                    fileOutPut.write(tempon, 0, nRead);
                }
                fileOutPut.close();
                returnInputStream = new FileInputStream(imageFile);
            }
        } catch (Exception e) {
            Log.e(LOG_TAG, "Error creating file", e);
        }
    }
    return returnInputStream;
}

From source file:com.c4mprod.utils.ImageDownloader.java

/**
 * Download the specified image from the Internet and binds it to the provided ImageView. The
 * binding is immediate if the image is found in the cache and will be done asynchronously
 * otherwise. A null bitmap will be associated to the ImageView if an error occurs.
 * //ww w  . ja v  a  2  s.c  o  m
 * @param url
 * @param imageView
 * @param subfolder
 *            the subfolder in sdcard cache
 * 
 */
public void download(String url, ImageView imageView, String subfolder) {
    if (subfolder != null) {
        mSubfolder = "/" + subfolder;
    } else {
        mSubfolder = "";
    }

    mfolder = Environment.getExternalStorageDirectory().getPath() + "/Android/data/"
            + imageView.getContext().getPackageName() + "/files/images" + mSubfolder;

    if (Environment.MEDIA_MOUNTED.equals(state)) {
        // We can read and write the media
        mExternalStorageAvailable = mExternalStorageWriteable = true;
        try {
            (new File(mfolder)).mkdirs();
            (new File(mfolder + "/.nomedia")).createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        // We can only read the media
        mExternalStorageAvailable = true;
        mExternalStorageWriteable = false;
    } else {
        // 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 = mExternalStorageWriteable = false;
    }

    resetPurgeTimer();
    Bitmap bitmap = getBitmapFromCache(url);

    if (bitmap == null) {
        forceDownload(url, imageView);
    } else {
        cancelPotentialDownload(url, imageView);
        imageView.setImageBitmap(bitmap);
        imageView.setBackgroundDrawable(null);
        if (listener != null) {
            listener.onImageDownloaded(imageView, url, mfolder + "/" + URLEncoder.encode(url),
                    imageView.getDrawable().getIntrinsicWidth(), imageView.getDrawable().getIntrinsicWidth());
        }
    }
}

From source file:com.kg.emailalbum.mobile.util.CacheManager.java

public File getOutboxDir() {
    String subdir = "created";
    // Default root is the application context internal files dir.
    File result = new File(mContext.getFilesDir(), subdir);

    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        // If an external storage is available, use it as it will prevent
        // from overloading the internal memory.
        result = new File(Environment.getExternalStorageDirectory(), "data/EmailAlbum/" + subdir);
    }/*w  w  w  . j av a2 s  . c o  m*/

    // Physically create the directory (and its parents) if it does not
    // exist.
    if (!result.exists()) {
        result.mkdirs();
    }

    // Log.i(LOG_TAG, "Using dir " + result + " for cache");
    return result;
}