android.os.Environment#MEDIA_UNMOUNTED源码实例Demo

下面列出了android.os.Environment#MEDIA_UNMOUNTED 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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();
}
 
源代码2 项目: Ezalor   文件: StorageUtils.java
private static String getExternalStorageState() {
    try {
        return Environment.getExternalStorageState();
    } catch (Exception e) {
        LogUtils.logeForce(e);
        return Environment.MEDIA_UNMOUNTED;
    }

}
 
源代码3 项目: Ezalor   文件: StorageUtils.java
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;
}
 
源代码4 项目: Beedio   文件: DownloadManager.java
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);
}