0
Even before version 6.0 the following method below works perfectly by downloading any document requested in Webview..
However now with android 6.0 in attempt to any download inside the webview the app hangs and says "The application has stopped working.".
The method below is in the same webview class.. Anyone knows how to download in android version 6?
//Método para download PDF
wv.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
DownloadManager.Request request = new DownloadManager.Request(
Uri.parse(url));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed!
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "boleto.pdf");
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 Arquivo", //To notify the Client that the file is being downloaded
Toast.LENGTH_LONG).show();
}
});
Edit the question and put the log error, I’m pretty sure it’s lack of permissions.
– ramaral
I researched better at night and really that was it. The new permissions system on Android 6 was blocking.. I added the permission request to record in memory in the MAIN class and now the webview downloads files as in previous verses.
– Jonatas Almeida