FileDocCategorySizeDatePackage
EnvironmentCompat.javaAPI DocAndroid 5.1 API2544Thu Mar 12 22:22:56 GMT 2015android.support.v4.os

EnvironmentCompat

public class EnvironmentCompat extends Object
Helper for accessing features in {@link Environment} introduced after API level 4 in a backwards compatible fashion.

Fields Summary
private static final String
TAG
public static final String
MEDIA_UNKNOWN
Unknown storage state, such as when a path isn't backed by known storage media.
Constructors Summary
Methods Summary
public static java.lang.StringgetStorageState(java.io.File path)
Returns the current state of the storage device that provides the given path.

return
one of {@link #MEDIA_UNKNOWN}, {@link Environment#MEDIA_REMOVED}, {@link Environment#MEDIA_UNMOUNTED}, {@link Environment#MEDIA_CHECKING}, {@link Environment#MEDIA_NOFS}, {@link Environment#MEDIA_MOUNTED}, {@link Environment#MEDIA_MOUNTED_READ_ONLY}, {@link Environment#MEDIA_SHARED}, {@link Environment#MEDIA_BAD_REMOVAL}, or {@link Environment#MEDIA_UNMOUNTABLE}.


                                                                                                              
         
        final int version = Build.VERSION.SDK_INT;
        if (version >= 19) {
            return EnvironmentCompatKitKat.getStorageState(path);
        }

        try {
            final String canonicalPath = path.getCanonicalPath();
            final String canonicalExternal = Environment.getExternalStorageDirectory()
                    .getCanonicalPath();

            if (canonicalPath.startsWith(canonicalExternal)) {
                return Environment.getExternalStorageState();
            }
        } catch (IOException e) {
            Log.w(TAG, "Failed to resolve canonical path: " + e);
        }

        return MEDIA_UNKNOWN;