检测web视图错误和显示信息 [英] Detecting Webview Error and Show Message
本文介绍了检测web视图错误和显示信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想显示错误信息时出现错误加载web视图页面(无连接)。这是我迄今为止,没有错误处理code:
I'd like to show an error message when there is an error loading a webview page (No connection). This is what I have so far, without the error handling code:
public class TrackerPage extends Activity {
// @Override
private WebView webview;
private ProgressDialog progressDialog;
private boolean error;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get rid of the android title bar
requestWindowFeature(Window.FEATURE_NO_TITLE);
// Set the XML layout
setContentView(R.layout.tracker_page);
// Bundle objectbundle = this.getIntent().getExtras();
webview = (WebView) findViewById(R.id.tracker);
final Activity activity = this;
// Enable JavaScript and lets the browser go back
webview.getSettings().setJavaScriptEnabled(true);
webview.canGoBack();
webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
public void onLoadResource(WebView view, String url) {
// Check to see if there is a progress dialog
if (progressDialog == null) {
// If no progress dialog, make one and set message
progressDialog = new ProgressDialog(activity);
progressDialog.setMessage("Loading please wait...");
progressDialog.show();
// Hide the webview while loading
webview.setEnabled(false);
}
}
public void onPageFinished(WebView view, String url) {
// Page is done loading;
// hide the progress dialog and show the webview
if (progressDialog.isShowing()) {
progressDialog.dismiss();
progressDialog = null;
webview.setEnabled(true);
}
}
});
// The URL that webview is loading
webview.loadUrl("http://url.org/");
}
}
我将如何做到这一点?
How would I do this?
推荐答案
您是最有路...只是实施<一个href="http://developer.android.com/reference/android/webkit/WebViewClient.html#onReceivedError%28android.webkit.WebView,%20int,%20java.lang.String,%20java.lang.String%29"><$c$c>onReceivedError$c$c>和处理所需的错误。
You're most of the way there... Just implement onReceivedError
and handle the errors that you want.
这篇关于检测web视图错误和显示信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文