Java Code Examples for android.os.storage.StorageManager#getStorageVolume()

The following examples show how to use android.os.storage.StorageManager#getStorageVolume() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Environment.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the current state of the shared/external storage media at the
 * given path.
 *
 * @return one of {@link #MEDIA_UNKNOWN}, {@link #MEDIA_REMOVED},
 *         {@link #MEDIA_UNMOUNTED}, {@link #MEDIA_CHECKING},
 *         {@link #MEDIA_NOFS}, {@link #MEDIA_MOUNTED},
 *         {@link #MEDIA_MOUNTED_READ_ONLY}, {@link #MEDIA_SHARED},
 *         {@link #MEDIA_BAD_REMOVAL}, or {@link #MEDIA_UNMOUNTABLE}.
 */
public static String getExternalStorageState(File path) {
    final StorageVolume volume = StorageManager.getStorageVolume(path, UserHandle.myUserId());
    if (volume != null) {
        return volume.getState();
    } else {
        return MEDIA_UNKNOWN;
    }
}
 
Example 2
Source File: Environment.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Returns whether the shared/external storage media at the given path is
 * physically removable.
 *
 * @return true if the storage device can be removed (such as an SD card),
 *         or false if the storage device is built in and cannot be
 *         physically removed.
 * @throws IllegalArgumentException if the path is not a valid storage
 *             device.
 */
public static boolean isExternalStorageRemovable(File path) {
    final StorageVolume volume = StorageManager.getStorageVolume(path, UserHandle.myUserId());
    if (volume != null) {
        return volume.isRemovable();
    } else {
        throw new IllegalArgumentException("Failed to find storage device at " + path);
    }
}
 
Example 3
Source File: Environment.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Returns whether the shared/external storage media at the given path is
 * emulated.
 * <p>
 * The contents of emulated storage devices are backed by a private user
 * data partition, which means there is little benefit to apps storing data
 * here instead of the private directories returned by
 * {@link Context#getFilesDir()}, etc.
 * <p>
 * This returns true when emulated storage is backed by either internal
 * storage or an adopted storage device.
 *
 * @throws IllegalArgumentException if the path is not a valid storage
 *             device.
 */
public static boolean isExternalStorageEmulated(File path) {
    final StorageVolume volume = StorageManager.getStorageVolume(path, UserHandle.myUserId());
    if (volume != null) {
        return volume.isEmulated();
    } else {
        throw new IllegalArgumentException("Failed to find storage device at " + path);
    }
}