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.blork.anpod.util.BitmapUtils.java

private static void manageCache(String slug, Context context) {
    String filename = slug + ".jpg";
    File folder;/*from w  w  w. j a v a  2  s .  co m*/
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        folder = new File(Environment.getExternalStorageDirectory() + File.separator + "Android"
                + File.separator + "data" + File.separator + "com.blork.anpod" + File.separator + "cache");
    } else {
        folder = context.getCacheDir();
    }

    int cacheSize = 15;
    Log.w("", "current file: " + filename);
    Log.w("", "Managing cache");
    File[] files = folder.listFiles();
    if (files == null || files.length <= cacheSize) {
        Log.w("", "Cache size is fine");
        return;
    }

    int count = files.length;

    Arrays.sort(files, new Comparator<File>() {
        public int compare(File f1, File f2) {
            return Long.valueOf(f1.lastModified()).compareTo(f2.lastModified());
        }
    });

    for (File f : files) {
        if (count > cacheSize && !filename.equals(f.getName())) {
            Log.w("", "Deleting " + f.getName());
            f.delete();
            count--;
        }
    }
}

From source file:com.zia.freshdocs.widget.CMISAdapter.java

/**
 * Retrieve the children from the specified node.  
 * @param position n-th child position/*  w ww .j  a  v  a  2 s . co m*/
 */
public void getChildren(int position) {
    final NodeRef ref = getItem(position);

    // For folders display the contents for the specified URI
    if (ref.isFolder()) {
        _stack.push(_currentState);
        String uuid = ref.getContent();
        _currentState = new Pair<String, NodeRef[]>(uuid, null);
        getChildren(uuid);
    }
    // For non-folders try a download (if there is an external storage card)
    else {
        String storageState = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(storageState)) {
            downloadContent(ref, new Handler() {
                public void handleMessage(Message msg) {
                    boolean done = msg.getData().getBoolean("done");
                    if (done) {
                        dismissProgressDlg();

                        File file = (File) _dlThread.getResult();
                        if (file != null) {
                            viewContent(file, ref);
                        }
                    } else {
                        int value = msg.getData().getInt("progress");
                        if (value > 0) {
                            _progressDlg.setProgress(value);
                        }
                    }
                }
            });
        }
    }
}

From source file:com.ibm.watson.developer_cloud.android.text_to_speech.v1.TTSUtility.java

/**
 * Get storage path/*from  w w  w.  j a v a 2s.co  m*/
 * @return
 */
private String getBaseDir() {
    String baseDir;
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        baseDir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/";
    } else {
        baseDir = "/data/data/" + getApplicationContext().getPackageName() + "/";
    }

    return baseDir;
}

From source file:com.mobicage.rogerthat.util.CachedDownloader.java

private CachedDownloader(MainService mainService) {
    this.mMainService = mainService;
    if (IOUtils.shouldCheckExternalStorageAvailable()) {
        String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state)) {
            this.mExternalStorageWriteable = true;
        } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
            this.mExternalStorageWriteable = false;
        } else {//  w  w w . j av a2 s . com
            this.mExternalStorageWriteable = false;
        }
    } else {
        this.mExternalStorageWriteable = true;
    }
}

From source file:com.bourke.kitchentimer.utils.Utils.java

public static boolean isSdPresent() {
    return Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
}

From source file:com.wso2.mobile.mdm.api.DeviceInfo.java

/**
*Returns whether the external memory is available or not
*//* w w  w  .j ava 2  s. c o  m*/
public boolean externalMemoryAvailable() {
    return android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
}

From source file:com.zia.freshdocs.widget.adapter.CMISAdapter.java

/**
 * Retrieve the children from the specified node.
 * /*  w w  w  . j av  a  2  s.co m*/
 * @param position
 *            n-th child position
 */
public void getChildren(int position) {
    final NodeRef ref = getItem(position);

    // For folders display the contents for the specified URI
    if (ref.isFolder()) {
        mStack.push(mCurrentState);
        String uuid = ref.getContent();
        mCurrentState = new Pair<String, NodeRef[]>(uuid, null);
        getChildren(uuid);
    }
    // For non-folders try a download (if there is an external storage card)
    else {
        String storageState = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(storageState)) {
            downloadContent(ref, new Handler() {
                public void handleMessage(Message msg) {
                    boolean done = msg.getData().getBoolean("done");
                    if (done) {
                        dismissProgressDlg();

                        File file = (File) mDlThread.getResult();
                        if (file != null) {
                            viewContent(file, ref);
                        }
                    } else {
                        int value = msg.getData().getInt("progress");
                        if (value > 0) {
                            mProgressDlg.setProgress(value);
                        }
                    }
                }
            });
        }
    }
}

From source file:cmu.troy.applogger.AppService.java

private boolean checkExternalStorageAvailable() {
    boolean mExternalStorageAvailable = false;
    boolean mExternalStorageWriteable = false;
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        mExternalStorageAvailable = mExternalStorageWriteable = true;
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        mExternalStorageAvailable = true;
        mExternalStorageWriteable = false;
    } else {//from w  w  w.  j a v a  2 s.c o  m
        mExternalStorageAvailable = mExternalStorageWriteable = false;
    }
    if (!(mExternalStorageAvailable && mExternalStorageWriteable)) {
        return false;
    } else
        return true;
}

From source file:com.att.android.arodatacollector.utils.AROCollectorUtils.java

/**
 * Returns a value indicating whether or not the device SD card is mounted.
 * /*w  w w  .  j ava 2  s. c  o m*/
 * @return A boolean value that is "true" if the SD card is mounted, and
 *         "false" if it is not.
 */
public boolean checkSDCardMounted() {
    final String state = Environment.getExternalStorageState();
    if (state.equals(Environment.MEDIA_REMOVED) || !state.equals(Environment.MEDIA_MOUNTED)
            || state.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
        return true;
    } else {
        return false;
    }
}

From source file:com.logilite.vision.camera.CameraLauncher.java

private String getTempDirectoryPath() {
    File cache = null;/*w ww .  j  av  a 2 s  .  c o  m*/

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

    // Create the cache directory if it doesn't exist
    cache.mkdirs();
    return cache.getAbsolutePath();
}