超时上的WebView的Android [英] Timeout on webview Android
问题描述
有没有办法来设置的WebView的超时值?我想要的WebView被时间驱赶出局,如果URL是在10秒内速度太慢,反应,或者如果网站不负载。
Is there a way to set the timeout value in WebView? I want the WebView to be time-outed if the url is too slow to response or if the site doesnt load in 10 seconds.
我真的不知道我应该开始:(
i dont know really where i should start :(
BTW我有2个班,其中一个是起动器和2一个是网页流量。起动器是一种线程和启动画面的启动和2.activity是主要的WebView,所以我想补充一个检查,如果在4秒10的网站不响应,它会给一个错误。
btw i have 2 classes, one of them is starter and the 2. one is for webview. starter is a kind of thread and splash-screen for start and the 2.activity is the main webview, so i would like to add a checker if the site doesnt response in 4 10 secs, it would give a error.
我希望所有的U可以帮助我,
i hope any of u can help me ,
推荐答案
Darpans code都不行,至少不因为虽然参数进度不会在修改
,只有通过下一个电话。试试这个:
Darpans code will not work, not at least because the parameter progress will not change during while
, only by next call of. Try this instead:
private long starttime = 0;
public void onProgressChanged(WebView view, int progress) {
Log.v(TAG, "progressChanged: " + progress);
if(progress == 10) starttime = System.currentTimeMillis();
long secondsSinceStart = (System.currentTimeMillis() - starttime) / 1000;
if(progress < 100) {
Log.v(TAG, "seconds since start: " + secondsSinceStart);
if(secondsSinceStart > 5){
view.stopLoading();
Log.d(TAG, "TIMEOUT -> Stopped.");
}
} else {
Log.v(TAG, progress + "% completed in: " + secondsSinceStart + " seconds");
}
}
不幸的是如果到服务器的连接将被建立,这只会工作。如果不是 onProgressChanged
被调用只有两次:10和100百分比时,则负载中止
Unfortunately this will only work if the connection to the server will be established. If not the onProgressChanged
get called only two times: at 10 and at 100 percents when then load is aborted.
这篇关于超时上的WebView的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!