I created a simple webView App which points to our onlineshop.
Problem:
We offer some files on our Download page, but I can't download any of them via the App while it works with the smartphones Chrome browser.
HTML:
<a class="thirdbox" href="/media/wysiwyg/pdf/systemaufbau-anleitungen.pdf" target="_blank" download="blizz-z_Systemaufbau_Anleitungen" title="Datei downloaden">
<div class="iconlink">
<p>Systemaufbau Anwendungsbroschüre<br><span style="font-size: 75%;">(PDF 5,8 MB)</span></p>
</div>
</a>
I am using this code, which also fixes the bug that links like tel:
or mailto:
can't get loaded.
But the function shouldOverrideUrlLoading
is not getting entered if I click on a link on that page. I set a breakpoint at the log statement and it is never triggered.
myWebView.setWebViewClient(new WebViewClient() {
...
// Give the host application a chance to take control when a URL is about to be loaded in the current WebView.
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
Log.i("debug_log", "shouldOverrideUrlLoading");
// Allow download of .pdf files
if (url.endsWith(".pdf")) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
// if want to download pdf manually create AsyncTask here
// and download file
return true;
}
// Allow URL's starting with /
if (url.startsWith("/")) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(website + url)));
// if want to download pdf manually create AsyncTask here
// and download file
return true;
}
// Also allow urls not starting with http or https (e.g. tel, mailto, ...)
if( URLUtil.isNetworkUrl(url) ) {
return false;
} else {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
}
return true;
}
});
This is getting logged into the logcat console if I click on a file link:
Received RST for invalid stream
I figured out that it is because of the html download
tag
If I remove it, then It works because the webview does not support it.
<a class="thirdbox"
href="/media/wysiwyg/pdf/systemaufbau-anleitungen.pdf"
target="_blank" download="Systemaufbau_Anleitungen" title="Datei downloaden">...</a>
↑
Problem