Example usage for android.support.v4.os EnvironmentCompat MEDIA_UNKNOWN

List of usage examples for android.support.v4.os EnvironmentCompat MEDIA_UNKNOWN

Introduction

In this page you can find the example usage for android.support.v4.os EnvironmentCompat MEDIA_UNKNOWN.

Prototype

String MEDIA_UNKNOWN

To view the source code for android.support.v4.os EnvironmentCompat MEDIA_UNKNOWN.

Click Source Link

Usage

From source file:uk.ac.ucl.excites.sapelli.collector.CollectorApp.java

/**
 * Check if a directory is on a mounted storage and writable/readable
 * //w  ww .  ja v  a2  s  . co m
 * @param dir
 * @return
 * @throws FileStorageException
 */
private boolean isMountedReadableWritableDir(File dir) throws FileStorageException {
    try {
        return // Null check:
        (dir != null)
                // Try to create the directory if it is not there
                && FileHelpers.createDirectory(dir)
                /* Check storage state, accepting both MEDIA_MOUNTED and MEDIA_UNKNOWN.
                *    The MEDIA_UNKNOWN state occurs when a path isn't backed by known storage media; e.g. the SD Card on
                * the Samsung Xcover 2 (the detection of which we have to force in DeviceControl#getExternalFilesDirs()). */
                && (Environment.MEDIA_MOUNTED.equals(EnvironmentCompat.getStorageState(dir))
                        || EnvironmentCompat.MEDIA_UNKNOWN.equals(EnvironmentCompat.getStorageState(dir)))
                // Check whether we have read & write access to the directory:
                && FileHelpers.isReadableWritableDirectory(dir);
    } catch (Exception e) {
        throw new FileStorageException("Unable to create or determine status of directory: "
                + (dir != null ? dir.getAbsolutePath() : "null"), e);
    }
}