我搜索并没有找到任何可以帮助我解答的问题。
我的WebView
代码:
webView = (WebView) findViewById(R.id.webView1);
webView.setWebViewClient(new WebViewClient());
WebView webView = (WebView) findViewById(R.id.webView1);
initWebView(webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setAppCacheMaxSize(1024*1024*8);
webView.getSettings().setAppCachePath("/cache/");
webView.getSettings().setAppCacheEnabled(true);
webView.loadUrl("http://google.com");
webView.setWebViewClient(new WebViewClient());
答案 0 :(得分:2)
使用此
ConnectivityManager connectivityManager = (ConnectivityManager) this.getSystemService(Activity.CONNECTIVITY_SERVICE);
if(connectivityManager.getActiveNetworkInfo().isConnected()){
mfnWebView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
mfnWebView.loadUrl(url);
}
else{
mfnWebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
mfnWebView.loadUrl(url);
}
强制权限: - INTERNET,ACCESS_NETWORK_STATE,ACCESS_WIFI_STATE