1

Are the cookies kept persistent when we use this? Are the cookies still available even after the phone restarts? I am referring to this link: http://developer.android.com/reference/android/webkit/CookieSyncManager.html

Say we are using DefaultHttpClient, CookieSyncManager would know to grab the cookies or are there other commands then the ones in the link that we will still need to provoke? How do we get the cookies back?

Noman Arain
  • 1,172
  • 4
  • 19
  • 45
  • Maybe this can help: http://stackoverflow.com/questions/4082799/android-how-to-store-cookies – 0gravity Jul 17 '12 at 01:58
  • I'm more specifically interested in the CookieSyncManager. Looking here: stackoverflow.com/a/3587332/9636 Is he using the CookieSyncManager – Noman Arain Jul 17 '12 at 02:08

2 Answers2

1

According to Cookies & Webview - CookieSyncManager in Android! it seems that CookieSyncManager works with the android's built webview:

CookieSyncManager.createInstance(webview.this);

So this is not something one would use if their app is not based on the webview.

Community
  • 1
  • 1
Noman Arain
  • 1,172
  • 4
  • 19
  • 45
  • 1
    Though it can be used to assist WebViews, it is not limited to only them. To your original question, I don't think they would persist after a phone restart, but if you need something like that, you might look into SharedPreferences. – eternalmatt Jul 18 '12 at 13:52
  • 1
    Can it be used when making HTTP call? – Noman Arain Jul 19 '12 at 12:03
1

try setting CookieSyncManager.getInstance().sync(); in the "onPageFinished" method, that worked for me like a charm, it mantaings the cookie even when restarted :)

here the code:

public void onCreate(Bundle savedInstanceState) {   
CookieSyncManager.createInstance(web.getContext());
        web = new WebView(this);  
        web.getSettings().setJavaScriptEnabled(true);
    web.loadUrl(url);
        web.setWebViewClient(new myWebClient());
...

}

public class myWebClient extends WebViewClient { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { // TODO Auto-generated method stub super.onPageStarted(view, url, favicon); }

    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        CookieSyncManager.getInstance().sync();
    }
}
Hiram
  • 2,679
  • 1
  • 16
  • 15