1
The App is a simple browser that works like Webview. This code makes the files to be downloaded into 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 they’re going for the cell phone memory. If your phone has a Sdcard inserted, how do I get the files to be downloaded directly to Sdcard?
This is to run on that version of Android(minimum version)?
– ramaral
It’s running at 2.3... minimum SDK 9...
– user41630
Why it has to be on Sdcard?
– ramaral
Because most cell phones have little internal memory.
– user41630
Are you sure you’re recording on the inside? What is the model of the device you tested?
– ramaral
Yes I do! I tested on G2 and G3 and LG-E410F
– user41630
You are wearing
request.setDestinationInExternalPublicDir()
which, as the name implies would be external memory. The problem is that newer devices may have more than one type of external memory. Besides the Sdcard, they may have some internal(fixed) considered with external. As I have never used the Downloadmanager I don’t know if that’s the problem. Now I don’t have time, tomorrow I’ll give you an answer to test.– ramaral
That may be! I await your answer!
– user41630