The App is a simple browser that works like WebView. This code causes the files to be downloaded to a custom folder and works perfectly.
mWebView.setDownloadListener(new DownloadListener() {
@SuppressLint("InlinedApi") public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
DownloadManager.Request request = new DownloadManager.Request(
Uri.parse(url));
request.allowScanningByMediaScanner();
final String filename = URLUtil.guessFileName(url, contentDisposition, mimetype);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed!
//request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);
request.setDestinationInExternalPublicDir("/Nome da Pasta", filename);
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); //This is important!
intent.addCategory(Intent.CATEGORY_OPENABLE); //CATEGORY.OPENABLE
intent.setType("*/*");//any application,any extension
Toast.makeText(getApplicationContext(), "Baixando", //To notify the Client that the file is being downloaded
Toast.LENGTH_LONG).show();
}
});
The problem is that they are going to the memory of the phone. If the phone has an SDCard inserted, how do I get the files to be downloaded directly to the SDCard?