我正在制作应用程序&我需要在2-3秒内刷新Webview。 如何使webview自动刷新 请用示例代码发布您的答案。谢谢。
这是我的代码......检查
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final WebView myWebView = (WebView) findViewById(R.id.myWebView);
The target url to surf using web view
String url = "www.mywebsite.com";
myWebView.loadUrl(url);
// Enable java script on web view
myWebView.setWebChromeClient(new WebChromeClient());
myWebView.setWebViewClient(new WebViewClient());
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setUserAgentString("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36");
final String js = ""
myWebView.setWebViewClient(new WebViewClient(){
/*
void onPageFinished (WebView view, String url)
public void onPageFinished(WebView view, String url){
super.onPageFinished(view, url);
if(url.contains("/nextpage")) {
myWebView.clearHistory();
myWebView.clearCache(true);
myWebView.clearView();
myWebView.destroy();
//finish();
//System.exit(0);
}
if(Build.VERSION.SDK_INT >= 19){
view.evaluateJavascript(js, new ValueCallback<String>() {
@Override
public void onReceiveValue(String s) {
}
});
}
}
});
}
}
答案 0 :(得分:0)
你能每隔2-3秒调用一次WebView.loadUrl()吗? 那是https://stackoverflow.com/a/2563482/2848676
的建议要安排定期刷新,您可以使用https://developer.android.com/reference/java/util/TimerTask.html