title: Android - extracting cookies after login in webview
body: <p>I have an application that opens a url in a webview, the user must then login to a site through the webview and receives a cookie once logged in. I'm having problems getting cookies after login.</p>
  
  <p>The problem is, I can achieve this using android.webkit.CookieManager, and output all cookies in a single string.</p>
  
  <p>However, I want to achieve it using the a cookie store (as in java.net.CookieStore) so I need to be using java.net.CookieManager.</p>
  
  <p>I'm using the following code within the onPageFinished() of a WebViewClient. I know the issue is with opening a new connection, where I need to be getting the content from the current page. I'd appreciate some help, thanks</p>
  
  <pre><code>        @Override
          public void onPageFinished(WebView view, String url){
  
              Log.d(TAG, "Finished loading: " + url);
  
              CookieSyncManager syncManager = CookieSyncManager.createInstance(Main.this);
              syncManager.sync();
  
              CookieManager manager = new CookieManager();
              manager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
              CookieHandler.setDefault(manager);
  
              try {
                  URL blah = new URL(url);
                  HttpURLConnection con = (HttpURLConnection) blah.openConnection();
                  readStream(con.getInputStream()); // outputting html
              } 
              catch (Exception e) {
              }
  
              CookieStore cookieJar = manager.getCookieStore();
              List&lt;HttpCookie&gt; cookies = cookieJar.getCookies();
  
              for (HttpCookie cookie: cookies) {
                  Log.d(TAG, "cookie name : "+cookie.getName().toString());
              }
          }
  </code></pre>