我有一个可浏览的 webview,但不幸的是,当我在 webview 中打开一个新页面时,我失去了登录状态,不得不再次登录。
这是我的代码:
wv = (WebView) findViewById(R.id.webArea);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
CookieManager.setAcceptFileSchemeCookies(true);
}
CookieSyncManager.createInstance(Home.this);
CookieSyncManager.getInstance().startSync();
dialog = new ProgressDialog(this);
dialog.setMessage("Loading");
dialog.setCanceledOnTouchOutside(false);
dialog.show();
wv.getSettings().setDatabaseEnabled(true);
wv.getSettings().setAllowFileAccess(true);
wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setLoadsImagesAutomatically(true);
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
dialog.show();
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
if (dialog.isShowing()) {
dialog.dismiss();
}
}
});
wv.loadUrl(url);
WebSettings webSettings = wv.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDatabaseEnabled(true);
webSettings.setAllowFileAccess(true);
怎么了?