您好,我尝试将正常的“无互联网连接”页面从 Android 浏览器更改为我的网络应用程序中的服装错误页面。在这样做时我发现了这个 link答案是将错误页面绑定(bind)到我的 Activity 中的一个很好的解决方案。
此解决方案的问题是我的网址 http://192.167.0.45/loc/index.php
不会加载,并且只有在任何几秒后才会加载文件 myerrorpage.html
变为显示。如何才能加载我的网址,而仅在错误情况下加载其他网址?看起来第二个 mWebview.loadUrl
覆盖了第一个...
@Override
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_localy);
mWebView = (WebView) findViewById(R.id.webview);
// Brower niceties -- pinch / zoom, follow links in place
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
mWebView.setWebViewClient(new GeoWebViewClient());
// Below required for geolocation
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setGeolocationEnabled(true);
mWebView.setWebChromeClient(new GeoWebChromeClient());
// Load google.com
mWebView.loadUrl("http://192.167.0.45/loc/index.php");
super.onCreate(savedInstanceState); mWebView.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
mWebView.loadUrl("file:///android_asset/myerrorpage.html");
}
});
}
最佳答案
看起来您无法加载您提供的网址,因此它跳转到 onReceivedError 方法,然后该方法显示 myerrorpage.html
。需要时间的原因是它必须确认它无法与主机建立连接。
关于java - 互联网连接异常失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33154338/