public static String getStorageState(File path) {
        if (Build.VERSION.SDK_INT >= 19) {
            return Environment.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;
    }
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}.
android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/compat/EnvironmentCompat.java