我正在尝试实现WebView
活动一切正常但是如果应用程序空闲30分钟并再次打开并点击它在浏览器中打开的任何链接并且它不会在所有SDK主要是Lollipop
以下是我使用的代码,我也使用了shouldOverrideUrlLoading
private void startWebView(String url) {
webView.setWebViewClient(new WebViewClient() {
ProgressDialog progressDialog;
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
public void onLoadResource(WebView view, String url) {
getBaseContext();
if (progressDialog == null) {
progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage("Loading...");
//progressDialog.show();
}
}
public void onPageFinished(WebView view, String url) {
try {
CookieSyncManager.getInstance().startSync();
CookieSyncManager.getInstance().sync();
//ImageView imgView = (ImageView)findViewById(R.id.imageView1);
//imgView.setVisibility(View.INVISIBLE);
if (progressDialog.isShowing()) {
progressDialog.dismiss();
progressDialog = null;
}
} catch (Exception exception) {
exception.printStackTrace();
}
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
startWebView("file:///android_asset/NoInternet.html");
}
});
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setRenderPriority(RenderPriority.HIGH);
webView.getSettings().setPluginState(
android.webkit.WebSettings.PluginState.ON_DEMAND);
webView.getSettings().setDatabaseEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setAppCacheMaxSize(1024 * 1024 * 8);
webView.getSettings().setDatabasePath("/data/data/" + webView.getContext().getPackageName() + "/databases/");
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setAppCacheEnabled(true);
WebView webview = new WebView(this);
WebSettings ws = webview.getSettings();
ws.setSaveFormData(true);
ws.setSavePassword(true );
webView.loadUrl(url);
// Log();
}