1

I want to save the downloaded file into a custom folder previously created as :

String trainingDirectory =  "swimmer" + File.separator + "trainings";
String trainingsPath = Environment.getExternalStorageDirectory().toString() + File.separator + trainingDirectory;           
File trainingSubdirectory = new File(getFilesDir() + File.separator + trainingsPath );
trainingSubdirectory.mkdirs();

to store the downloaded file into this directory, I tried to follow the solution given : Set custom folder Android Download Manager writing

request.setDestinationInExternalPublicDir ( "/trainings", "mydownloadedfile.mp4");

In this case , the download manager is creating a new 'training' directory , not using the one I created previously... I tried also to use

request.setDestinationInExternalPublicDir ( "/swimmer/trainings", "mydownloadedfile.mp4");

but in this case an error is raised ( a path with separators is not accepted..) where am I wrong ?

Community
  • 1
  • 1

1 Answers1

3

Use this:

String directoryPath = Environment.getExternalStorageDirectory() + "/swimmer/trainings/"
// ...
request.setDestinationUri(Uri.fromFile(new File(directoryPath + "fileName.ext")));
Ali Behzadian Nejad
  • 8,804
  • 8
  • 56
  • 106