保存Cookies Webview?

use*_*675 4 eclipse cookies android webview

我试图让这个WebView的Android代码保持会话cookie,以便当应用程序关闭,用户再次启动时,他们可以保持登录状态.我是非常新的,我很沮丧试图解决这个问题.我需要改变什么?请善待,因为我是一个白痴,请描述,即使你必须为我编辑,如果这对你来说更容易.

我导入了CookieManager和CookieSyncManager,但没有IDEA下一步该做什么.我已经阅读了所有文档,花了好几个小时试图弄清楚如何保存cookie,这样用户就不必再次登录了,我只是想不出来......

package com.template.WebViewTemplate;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;

public class WebViewTemplate extends Activity {
private WebView myWebView;
/** Called when the activity is first created. */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) { // Enables browsing to previous pages with the hardware back button
        myWebView.goBack();
        return true;
    }
    return super.onKeyDown(keyCode, event);
} 

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    myWebView = (WebView) findViewById(R.id.webview); // Create an instance of WebView and set it to the layout component created with id webview in main.xml
    myWebView.getSettings().setJavaScriptEnabled(true);
    myWebView.loadUrl("http://zuneboards.com/forums/mgc_chatbox.php?do=view_chatbox"); // Specify the URL to load when the application starts
    //myWebView.loadUrl("file://sdcard/"); // Specify a local file to load when the application starts. Will only load file types WebView supports
    myWebView.setWebViewClient(new WebViewKeep());
    myWebView.setInitialScale(1); // Set the initial zoom scale
    myWebView.getSettings().setBuiltInZoomControls(true); // Initialize zoom controls for your WebView component
    myWebView.getSettings().setUseWideViewPort(true); // Initializes double-tap zoom control

}

private class WebViewKeep extends WebViewClient {
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }
Run Code Online (Sandbox Code Playgroud)

}}

A-D*_*ech 5

您可以在Websetting中使用它:

webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
Run Code Online (Sandbox Code Playgroud)