自定义下载目录

时间:2018-04-05 18:06:17

标签: android download directory

我的应用已经创建了一个自定义目录,最好是在外部存储中:

public static File downloadDir;
public static String downloadStorage;
public static String downloadSubPath;

public static void checkDownloadDir(String subPath) {
        String downloadPath = "";
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            downloadStorage = Environment.getExternalStorageDirectory().getPath();
        } else {
            downloadStorage = Environment.DIRECTORY_DOWNLOADS;
        }
        downloadSubPath = subPath;
        downloadPath = downloadStorage + File.separator + downloadSubPath;
        downloadDir = new File(downloadPath);
        if (!downloadDir.exists()) {
            //Log.d("Directory", "creating directory");
            if (downloadDir.mkdirs()) {
                //Log.d("Directory", "directory created");
            } else {
                //Log.d("Directory", "directory not created");
            }
        } else {
            //Log.d("Directory", "directory exists");
        }
    }

在可用存储(downloadStorage)中创建自定义文件夹(downloadSubPath)后,如何使用此自定义路径(downloadStorage + File.separator + downloadSubPath或downloadDir.getPath())来保存最终用户可以使用的文件下载?。用户可以下载的文件可以是任何格式,.pdf,.jpg,.mp4,.doc等。或者将下载的文件从默认保存目录移动到目标目录?

0 个答案:

没有答案
相关问题