I am using Android DownloadManger System Service for downloading some files in following way
dwnId = mgr.enqueue(new DownloadManager.Request(serveruri)
A simple way to download your files, See download progress in notification bar and even open your file when it complete to download by just clicking it in the notification bar.
Just call this method and pass your filename and download url
public void downloadFile(String name, String url){
//download link
downloadUri = Uri.parse(url);
DownloadManager.Request request = new DownloadManager.Request(downloadUri);
//allow download to take place over wifi, mobile network and roaming
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE ).setAllowedOverRoaming(true);
request.setAllowedOverRoaming(false);
//name to show while downloading
request.setTitle(name);
//description to show while downloading
request.setDescription("Downloading " + name);
//show on navigation
request.setVisibleInDownloadsUi(true);
//download path
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS.toString(), "/" + name);
//file open when item on navigation is clicked
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
long downloadId = downloadManager.enqueue(request);
}
Output
You can learn more here