Set loadURLTImeOutValue on WebView

前端 未结 6 1126
我在风中等你
我在风中等你 2020-11-29 06:32

I\'m working with PhoneGap and Android and have my .html and js files on an external server. When I use the following code, the app loads my external .html files and everyt

6条回答
  •  没有蜡笔的小新
    2020-11-29 06:58

    I used this to set a time out for my WebView:

    public class MyWebViewClient extends WebViewClient {
    
        boolean timeout = true;
    
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            Runnable run = new Runnable() {
                public void run() {
                    if(timeout) {
                        // do what you want
                        showAlert("Connection Timed out", "Whoops! Something went wrong. Please try again later.");
                    }
                }
            };
            Handler myHandler = new Handler(Looper.myLooper());
            myHandler.postDelayed(run, 5000);
        }
    
        @Override
        public void onPageFinished(WebView view, String url) {
            timeout = false;
        }
    }
    

提交回复
热议问题