title: Pass cookies from native login to webview
body: <p>I am following <a href="http://blog.winfieldpeterson.com/2013/01/17/cookies-in-hybrid-android-apps/" rel="nofollow"><strong>this</strong></a> for sharing cookies from native code to <code>WebView</code>. I have a native login screen. On successful login I am saving the cookies in <code>CookieSyncManager</code>. And when the webview loads, I am passing those cookies to it so that the login screen does not appears.<br>
  Following is what I have implemented :  </p>
  
  <pre><code>public class MyApp extends Application {
      public void onCreate() {
          super.onCreate();
  
          //Setup Cookie Manager and Persistence to disk
          CookieSyncManager.createInstance(this);
          CookieManager.getInstance().setAcceptCookie(true);
      }
  }  
  </code></pre>
  
  <p><strong>HttpRequest for login</strong> :  </p>
  
  <pre><code>private void executeRequest(HttpUriRequest request, String url) {
          DefaultHttpClient client = getDefaultClient(); // new DefaultHttpClient();
  
          syncCookiesFromAppCookieManager(loginUrl, client);
  
          HttpResponse httpResponse = null;
  
          try {
              httpResponse = client.execute(request);
          } catch (IOException e1) {
              e1.printStackTrace();
          }
          responseCode = httpResponse.getStatusLine().getStatusCode();
          message = httpResponse.getStatusLine().getReasonPhrase();
  
          HttpEntity entity = httpResponse.getEntity();
  
          if (entity != null) {
  
              InputStream instream = null;
              try {
              instream = entity.getContent();
                } catch (IOException e1) {
                    e1.printStackTrace();
                  }
              response = convertStreamToString(instream);
              response = StringUtils.remove(response, "\n");
              syncCookiesFromAppCookieManager(loginUrl, client);
             // client.setCookieStore((org.apache.http.client.CookieStore) new PersistentCookieStore(context));
  
  
  
  }
      }  
  </code></pre>
  
  <p>And in <strong>WebActivity</strong> :  </p>
  
  <pre><code>CookieSyncManager.getInstance().sync();  
  webview.loadUrl(url);  
  </code></pre>
  
  <p>But I am again getting the login screen on <code>webView</code>. i.e. cookies are not getting stored.</p>