美文网首页
为 WebView 设置 TimeOut

为 WebView 设置 TimeOut

作者: zac4j | 来源:发表于2017-11-23 21:09 被阅读308次

设置 WebView 的 WebViewClient,在 WebViewClient::onPageStart 回调方法里:

private static final String TAG = "WebView";
private static final int TIME_OUT_PROGRESS = 30;
private static final int TIME_OUT_MILLIS = 2*1000;

@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
  super.onPageStarted(view, url, favicon);
  new Handler(Looper.getMainLooper())
    .postDelayed(new Runnable() {
      @Override
      public void run() {
        if (mWebView.getProgress() < TIME_OUT_PROGRESS) {
          Log.e(TAG, "connection time out ------ current progress is: ------" + mWebView.getProgress());
          // Todo timeout code logic
        }
      }
  }, TIME_OUT_MILLIS);
}

相关文章

网友评论

      本文标题:为 WebView 设置 TimeOut

      本文链接:https://www.haomeiwen.com/subject/hcetbxtx.html