[英]Webview sometimes shows webpage not available
On all of my apps I am getting a "webpage not available" error. 在我所有的应用程序上,我都收到“网页不可用”错误。 This has just been happening recently, even on apps that have not been updated in awhile.
这是最近才发生的,即使是在一段时间内未更新的应用程序上也是如此。 At first I thought it was my server or domain name.
起初我以为是我的服务器或域名。 However, everything loads on a mobile browser or desktop browser.
但是,所有内容都可以在移动浏览器或桌面浏览器上加载。 The strangest part is that I can click on the link for the website given by the error and it works.
最奇怪的部分是我可以单击错误给出的网站链接,并且可以正常工作。 Also, this isn't every time I get into the app.
另外,这并不是我每次都进入该应用程序。 It sometimes load without any problems at all.
有时加载时根本没有任何问题。
This is my main activity: 这是我的主要活动:
public class MainActivity extends Activity { private WebView mWebView; 公共类MainActivity扩展了Activity {private WebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Allow third party cookies for Android Lollipop
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mWebView = (WebView) findViewById(R.id.activity_main_webview);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptThirdPartyCookies(mWebView,true);
}
mWebView = (WebView) findViewById(R.id.activity_main_webview);
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
mWebView.getSettings().setAppCacheEnabled(true);
mWebView.getSettings().setDatabaseEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.loadUrl("http://www.google.com");
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && this.mWebView.canGoBack()) {
this.mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
} }
You instantiated WebView twice that could be the reason. 您实例化了WebView两次,这可能是原因。
cookieManager.setAcceptThirdPartyCookies(mWebView,true);
You don't need this one below, you've done it already. 您在下面不需要这个,您已经完成了。
mWebView = (WebView)findViewById(R.id.activity_main_webview);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.