public final class

EnvironmentCompat

extends java.lang.Object

 java.lang.Object

↳androidx.core.os.EnvironmentCompat

Gradle dependencies

compile group: 'androidx.core', name: 'core', version: '1.15.0-alpha02'

  • groupId: androidx.core
  • artifactId: core
  • version: 1.15.0-alpha02

Artifact androidx.core:core:1.15.0-alpha02 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.core:core com.android.support:support-compat

Androidx class mapping:

androidx.core.os.EnvironmentCompat android.support.v4.os.EnvironmentCompat

Overview

Helper for accessing features in .

Summary

Fields
public static final java.lang.StringMEDIA_UNKNOWN

Unknown storage state, such as when a path isn't backed by known storage media.

Methods
public static java.lang.StringgetStorageState(java.io.File path)

Returns the current state of the storage device that provides the given path.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Fields

public static final java.lang.String MEDIA_UNKNOWN

Deprecated: Use directly.

Unknown storage state, such as when a path isn't backed by known storage media.

See also: EnvironmentCompat.getStorageState(File)

Methods

public static java.lang.String getStorageState(java.io.File path)

Returns the current state of the storage device that provides the given path.

Returns:

one of , , , , , , , , , or .

Source

/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.core.os;

import android.os.Build;
import android.os.Environment;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;

import java.io.File;

/**
 * Helper for accessing features in {@link Environment}.
 */
public final class EnvironmentCompat {
    /**
     * Unknown storage state, such as when a path isn't backed by known storage
     * media.
     *
     * @see #getStorageState(File)
     *
     * @deprecated Use {@link Environment#MEDIA_UNKNOWN} directly.
     */
    @Deprecated
    public static final String MEDIA_UNKNOWN = "unknown";

    /**
     * Returns the current state of the storage device that provides the given
     * path.
     *
     * @return one of {@link Environment#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}.
     */
    @SuppressWarnings("deprecation")
    @NonNull
    public static String getStorageState(@NonNull File path) {
        if (Build.VERSION.SDK_INT >= 21) {
            return Api21Impl.getExternalStorageState(path);
        } else {
            return Environment.getStorageState(path);
        }
    }

    private EnvironmentCompat() {
    }

    @RequiresApi(21)
    static class Api21Impl {
        private Api21Impl() {
            // This class is not instantiable.
        }

        static String getExternalStorageState(File path) {
            return Environment.getExternalStorageState(path);
        }
    }
}