Example usage for android.os Environment MEDIA_MOUNTED_READ_ONLY

List of usage examples for android.os Environment MEDIA_MOUNTED_READ_ONLY

Introduction

In this page you can find the example usage for android.os Environment MEDIA_MOUNTED_READ_ONLY.

Prototype

String MEDIA_MOUNTED_READ_ONLY

To view the source code for android.os Environment MEDIA_MOUNTED_READ_ONLY.

Click Source Link

Document

Storage state if the media is present and mounted at its mount point with read-only access.

Usage

From source file:com.lazy.gank.logging.Logcat.java

public static Config defaultConfig() {
    Builder builder = newBuilder();/* ww w  .  ja v  a 2s . c  o m*/

    // ???
    do {
        String state = Environment.getExternalStorageState();
        //  SD ?
        if (!Environment.MEDIA_MOUNTED.equals(state)) {
            Log.w(TAG, "Not mount SD card!");
            break;
        }

        // SD ???
        if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
            Log.w(TAG, "Not allow write SD card!");
            break;
        }

        File externalCacheDir = mContext.getExternalCacheDir();
        // context.getExternalCacheDir() maybe null
        if (externalCacheDir != null) {
            builder.logSavePath = externalCacheDir.getAbsolutePath() + FILE_SEPARATOR + DEFAULT_LOG_DIR;
        } else {
            Log.e(TAG, "externalCacheDir is null!");
            builder.fileLogLevel(OPERATION_BIT);
            break;
        }

        // ? SD ?????
        // ???? ? SD ? Cache/Log 
        String strSaveLogPath = builder.logSavePath;

        checkSaveLogPath(strSaveLogPath);
    } while (false);

    Config config = new Config(builder);
    return config;
}

From source file:com.tzutalin.example.MainActivity.java

@DebugLog
private boolean isExternalStorageReadable() {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        return true;
    }/* w w w .j  a v a  2 s  .co m*/
    return false;
}

From source file:com.example.android.wearable.runtimepermissions.IncomingRequestPhoneService.java

private boolean isExternalStorageReadable() {
    String state = Environment.getExternalStorageState();

    return Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state);
}

From source file:dev.dworks.apps.anexplorer.provider.ExternalStorageProvider.java

@TargetApi(Build.VERSION_CODES.KITKAT)
private void updateVolumesLocked() {
    mRoots.clear();//  w w w.  j  ava2s.  c o m
    mIdToPath.clear();
    mIdToRoot.clear();

    int count = 0;
    StorageUtils storageUtils = new StorageUtils(getContext());
    for (StorageVolume volume : storageUtils.getStorageMounts()) {
        final File path = volume.getPathFile();
        String state = EnvironmentCompat.getStorageState(path);
        final boolean mounted = Environment.MEDIA_MOUNTED.equals(state)
                || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state);
        if (!mounted)
            continue;

        final String rootId;
        final String title;
        if (volume.isPrimary && volume.isEmulated) {
            rootId = ROOT_ID_PRIMARY_EMULATED;
            title = getContext().getString(R.string.root_internal_storage);
        } else if (volume.getUuid() != null) {
            rootId = ROOT_ID_SECONDARY + volume.getLabel();
            String label = volume.getLabel();
            title = !TextUtils.isEmpty(label) ? label
                    : getContext().getString(R.string.root_external_storage) + (count > 0 ? " " + count : "");
            count++;
        } else {
            Log.d(TAG, "Missing UUID for " + volume.getPath() + "; skipping");
            continue;
        }

        if (mIdToPath.containsKey(rootId)) {
            Log.w(TAG, "Duplicate UUID " + rootId + "; skipping");
            continue;
        }

        try {
            if (null == path.listFiles()) {
                continue;
            }
            mIdToPath.put(rootId, path);
            final RootInfo root = new RootInfo();

            root.rootId = rootId;
            root.flags = Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_EDIT | Root.FLAG_LOCAL_ONLY
                    | Root.FLAG_ADVANCED | Root.FLAG_SUPPORTS_SEARCH | Root.FLAG_SUPPORTS_IS_CHILD;
            root.title = title;
            root.docId = getDocIdForFile(path);
            root.path = path.getPath();
            mRoots.add(root);
            mIdToRoot.put(rootId, root);
        } catch (FileNotFoundException e) {
            throw new IllegalStateException(e);
        }
    }

    Log.d(TAG, "After updating volumes, found " + mRoots.size() + " active roots");

    getContext().getContentResolver().notifyChange(DocumentsContract.buildRootsUri(AUTHORITY), null, false);
}

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 {//from   w  ww .  j a v  a  2 s  .  com
            this.mExternalStorageWriteable = false;
        }
    } else {
        this.mExternalStorageWriteable = true;
    }
}

From source file:org.legacyxperia.center.BugReport.java

private short sdAvailable() {
    // Check if SD card is available
    // Taken from developer.android.com
    short mExternalStorageAvailable = 0;
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        // We can read and write the media
        mExternalStorageAvailable = 2;/*from  w ww . j  ava  2 s .c o m*/
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        // We can only read the media
        mExternalStorageAvailable = 1;
    } 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 = 0;
    }
    return mExternalStorageAvailable;
}

From source file:org.jinzora.util.DrawableManager.java

private InputStream fetch(String urlString) throws MalformedURLException, IOException {
    String state = Environment.getExternalStorageState();
    if (!externalStorageAvailable()) {
        if (DBG)//w ww.j ava  2s . c o m
            Log.d(TAG, "External storage not available; fetching from network");
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpGet request = new HttpGet(urlString);
        HttpResponse response = httpClient.execute(request);
        return response.getEntity().getContent();
    }

    File thumbFile = getLocalFile(urlString);
    if (thumbFile.exists()) {
        return new FileInputStream(thumbFile);
    }

    if (!cacheToDisk || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        if (DBG)
            Log.d(TAG, "Fetching from network and not writing to disk");
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpGet request = new HttpGet(urlString);
        HttpResponse response = httpClient.execute(request);
        return response.getEntity().getContent();
    } else {
        if (DBG)
            Log.d(TAG, "Fetching from network and storing on disk");
        File thumbDir = thumbFile.getParentFile();
        if (!thumbDir.exists()) {
            thumbDir.mkdirs();
        }
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpGet request = new HttpGet(urlString);
        HttpResponse response = httpClient.execute(request);
        InputStream is = response.getEntity().getContent();

        OutputStream out = new FileOutputStream(thumbFile);
        byte[] buf = new byte[1024];
        int len;
        while ((len = is.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        out.close();
        return new FileInputStream(thumbFile);
    }
}

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

/**
 * Returns a value indicating whether or not the device SD card is mounted.
 * //from   ww w  .  j av a2s  .  co 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: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 ww . j  av a 2s.co  m
        mExternalStorageAvailable = mExternalStorageWriteable = false;
    }
    if (!(mExternalStorageAvailable && mExternalStorageWriteable)) {
        return false;
    } else
        return true;
}

From source file:at.jclehner.rxdroid.Backup.java

public static String getStorageState() {
    final String state;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
        state = Environment.getStorageState(DIRECTORY);
    else/* w  w  w  .j a v  a 2  s  .  c  o  m*/
        state = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(state) && !DIRECTORY.canWrite()) {
        Log.d(TAG, "Storage state reported as MEDIA_MOUNTED, but " + DIRECTORY + " is not writeable");

        return Environment.MEDIA_MOUNTED_READ_ONLY;
    }

    return state;
}