http://www.cnblogs.com/sunzn/archive/2013/04/03/2998113.html
mWebView.setWebViewClient(new MyWebViewClient());
mWebView.loadUrl(url);
最近做项目在手机端加载一个 WebView 进行网页第三方登录的时候,认证成功后会跳转到公司的网页中,手机客户端需要从网页中拿到 Cookies 携带的 UID 进行数据交互,这时我们可以在 WebViewClient 的 onPageFinished(WebView view, String url) 方法中使用 CookieManager 来获取加载完成之后网页中携带的 Cookie 值,代码如下:
private class MyWebViewClient extends WebViewClient { public boolean shouldOverrideUrlLoading(WebView view, String url) {
webview.loadUrl(url);
return true;
} public void onPageFinished(WebView view, String url) {
CookieManager cookieManager = CookieManager.getInstance();
String CookieStr = cookieManager.getCookie(url);
Log.e("sunzn", "Cookies = " + CookieStr);
super.onPageFinished(view, url);
} }