Java Code Examples for android.os.Environment#MEDIA_UNMOUNTED

The following examples show how to use android.os.Environment#MEDIA_UNMOUNTED . 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: DefaultConnectableDeviceStore.java    From Connect-SDK-Android-Core with Apache License 2.0 6 votes vote down vote up
public DefaultConnectableDeviceStore(Context context) { 
    String dirPath;
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        dirPath = Environment.getExternalStorageDirectory().getAbsolutePath();
    }
    else {
        dirPath = Environment.MEDIA_UNMOUNTED;
    }
    fileFullPath = dirPath + DIRPATH + FILENAME;

    try {
        fileFullPath = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).applicationInfo.dataDir + "/" + FILENAME;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    load();
}
 
Example 2
Source File: StorageUtils.java    From Ezalor with Apache License 2.0 5 votes vote down vote up
private static String getExternalStorageState() {
    try {
        return Environment.getExternalStorageState();
    } catch (Exception e) {
        LogUtils.logeForce(e);
        return Environment.MEDIA_UNMOUNTED;
    }

}
 
Example 3
Source File: StorageUtils.java    From Ezalor with Apache License 2.0 5 votes vote down vote up
public static String getStorageState(Context context, String path) {
    String state = Environment.MEDIA_UNMOUNTED;
    StorageManager storageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
    try {
        Class<?>[] paramClasses = {String.class};
        Method getVolumeStateMethod = StorageManager.class.getMethod("getVolumeState", paramClasses);
        getVolumeStateMethod.setAccessible(true);
        state = (String) getVolumeStateMethod.invoke(storageManager, path);
    } catch (Exception exception) {
        LogUtils.logeForce(exception);
    }
    return state;
}
 
Example 4
Source File: DownloadManager.java    From Beedio with GNU General Public License v2.0 4 votes vote down vote up
private static File prepareTargetDirectory() throws DownloadFailException, IOException {
    File downloadFolder =
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
    if (
            downloadFolder
                    != null
                    && (downloadFolder.exists() || downloadFolder.mkdir() || downloadFolder.createNewFile())
                    && downloadFolder.canWrite()
    ) {
        return downloadFolder;
    }

    File externalStorage = Environment.getExternalStorageDirectory();
    String externalStorageState = Environment.getExternalStorageState();
    if (
            externalStorage
                    != null
                    && (externalStorage.exists() || externalStorage.mkdir() || externalStorage.createNewFile())
                    && externalStorage.canWrite()
                    && externalStorageState.equals(Environment.MEDIA_MOUNTED)
    ) {
        return new File(externalStorage, "Download");
    }

    File appExternal = LMvdApp.getInstance().getExternalFilesDir(null);
    if (
            appExternal
                    != null
                    && (appExternal.exists() || appExternal.mkdir() || appExternal.createNewFile())
                    && appExternal.canWrite()
    ) {
        return new File(appExternal, "Download");
    }

    String message;
    switch (externalStorageState) {
        case Environment.MEDIA_UNMOUNTABLE:
            message = "External storage is un-mountable.";
            break;
        case Environment.MEDIA_SHARED:
            message = "USB mass storage is turned on. Can not mount external storage.";
            break;
        case Environment.MEDIA_UNMOUNTED:
            message = "External storage is not mounted.";
            break;
        case Environment.MEDIA_MOUNTED_READ_ONLY:
            message = "External storage is mounted but has no write access.";
            break;
        case Environment.MEDIA_BAD_REMOVAL:
            message = "External storage was removed without being properly ejected.";
            break;
        case Environment.MEDIA_REMOVED:
            message = "External storage does not exist. Probably removed.";
            break;
        case Environment.MEDIA_NOFS:
            message = "External storage is blank or has unsupported filesystem.";
            break;
        case Environment.MEDIA_CHECKING:
            message = "Still checking for external storage.";
            break;
        case Environment.MEDIA_EJECTING:
            message = "External storage is currently being ejected.";
            break;
        case Environment.MEDIA_UNKNOWN:
            message = "External storage is not available for some unknown reason.";
            break;
        case Environment.MEDIA_MOUNTED:
            message = "External storage is mounted but for some unknown reason is not" +
                    " available.";
            break;
        default:
            message = "External storage is not available. No reason.";
    }
    throw new DownloadFailException(message);
}