Android WebView获取cookie

2022-06-10 12:16:26 浏览数 (1)

重写WebViewClient方法

代码语言:javascript复制
public class MyWebViewClient extends WebViewClient {

    public boolean shouldOverrideUrlLoading(WebView webview, String url) {
        webview.loadUrl(url);
        return true;
    }

    public void onPageFinished(WebView view, String url) {
        CookieManager cookieManager = CookieManager.getInstance();
        String CookieStr = cookieManager.getCookie(url);
        LogUtil.i("Cookies", "Cookies = "   CookieStr);
        super.onPageFinished(view, url);
    }

}

调用

代码语言:javascript复制
mWebView.setWebViewClient(new MyWebViewClient());

0 人点赞