Java Code Examples for android.os.Environment#MEDIA_UNMOUNTED

The following examples show how to use android.os.Environment#MEDIA_UNMOUNTED . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
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 Project: Ezalor   File: StorageUtils.java    License: 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 Project: Ezalor   File: StorageUtils.java    License: 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
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);
}