Android webView - 无法加载某些链接 - 收到无效流的 RST
Android webView - Can't load some links - Received RST for invalid stream
我创建了一个指向我们在线商店的简单 webView 应用程序。
问题:
我们在 Download page 上提供了一些文件,但是当它与智能手机 Chrome 浏览器配合使用时,我无法通过该应用程序下载任何文件。
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>
我正在使用此代码,它还修复了 link 等 tel:
或 mailto:
无法加载的错误。
但是如果我在该页面上单击 link,则不会输入函数 shouldOverrideUrlLoading
。我在log语句下了断点,一直没有触发。
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;
}
});
如果我单击文件 link:
,这将登录到 logcat 控制台
Received RST for invalid stream
我发现是因为html download
标签
如果我删除它,那么它可以工作,因为 webview 不支持它。
<a class="thirdbox"
href="/media/wysiwyg/pdf/systemaufbau-anleitungen.pdf"
target="_blank" download="Systemaufbau_Anleitungen" title="Datei downloaden">...</a>
↑
Problem
我创建了一个指向我们在线商店的简单 webView 应用程序。
问题:
我们在 Download page 上提供了一些文件,但是当它与智能手机 Chrome 浏览器配合使用时,我无法通过该应用程序下载任何文件。
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>
我正在使用此代码,它还修复了 link 等 tel:
或 mailto:
无法加载的错误。
但是如果我在该页面上单击 link,则不会输入函数 shouldOverrideUrlLoading
。我在log语句下了断点,一直没有触发。
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;
}
});
如果我单击文件 link:
,这将登录到 logcat 控制台Received RST for invalid stream
我发现是因为html download
标签
如果我删除它,那么它可以工作,因为 webview 不支持它。
<a class="thirdbox"
href="/media/wysiwyg/pdf/systemaufbau-anleitungen.pdf"
target="_blank" download="Systemaufbau_Anleitungen" title="Datei downloaden">...</a>
↑
Problem