嗯,我想获取 webview 的页面加载时间并检查它是否等于超时时间,但我不知道该怎么做,请帮助我。
maybe you should use a Timer
and listener on your webview
start timer as soon as the webview start loading your page , and stop it when it's done
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url) {
//start timer here
}
@Override
public void onPageFinished(WebView view, String url) {
// stop timer here
}
});
Create subclass for WebViewClient
and override onPageLoadStarted
onPageLoadFinished
methods. (Exact method names I don't remember.)
Attach subclass of WebViewClient
to your WebView
.
Write logic to find the time to load from page load start to page load finish.
`
mWebView.setWebViewClient(new WebViewClient() {
long pageLoadStartTime;
@Override
public void onPageStarted(WebView view, String url) {
pageLoadStartTime = System.currentTimeMillis();
}
@Override
public void onPageFinished(WebView view, String url) {
long pageLoadTime = System.currentTimeMillis() - pageLoadStartTime;
//pageLoadTime is you required data in milliseconds
}
});
`
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.