我想将下载的文件保存到以前创建的自定义文件夹中:
String trainingDirectory = "swimmer" + File.separator + "trainings";
String trainingsPath = Environment.getExternalStorageDirectory().toString() + File.separator + trainingDirectory;
File trainingSubdirectory = new File(getFilesDir() + File.separator + trainingsPath );
trainingSubdirectory.mkdirs();
将下载的文件存储到此目录中,我尝试按照给出的解决方案:Set custom folder Android Download Manager 写作
request.setDestinationInExternalPublicDir ( "/trainings", "mydownloadedfile.mp4");
在这种情况下,下载管理员正在创建一个新的培训'目录,不使用我之前创建的那个... 我也尝试使用
request.setDestinationInExternalPublicDir ( "/swimmer/trainings", "mydownloadedfile.mp4");
但在这种情况下会引发错误(不接受带分隔符的路径..) 我哪里错了?
答案 0 :(得分:1)
使用此:
String directoryPath = Environment.getExternalStorageDirectory() + "/swimmer/trainings/"
// ...
request.setDestinationUri(Uri.fromFile(new File(directoryPath + "fileName.ext")));