I am using the following code to download a file from my server then write it to the root directory of the SD card, it all works fine:
package com.downloader;
In order to download a file to Download or Music Folder In SDCard
File downlodDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);// or DIRECTORY_PICTURES
And dont forget to add these permission in manifest