setting Cookies in WebView android

前端 未结 2 1087
难免孤独
难免孤独 2020-12-14 20:01

I\'m trying to set some cookies on my WebView to open a browser with the same session that I have on my app.

I read a lot of answers but they don\'t wo

相关标签:
2条回答
  • 2020-12-14 20:31
    CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(mWebView.getContext());
    ...
    cookieSyncManager.sync();
    

    is the cause of problem. You should do like this:

    CookieSyncManager.createInstance(mWebView.getContext());
    ...
    CookieSyncManager.getInstance().sync();
    

    And there will be no need to manually create WebView...

    0 讨论(0)
  • 2020-12-14 20:46

    Solved!!!! the problem is with the webView, I dont know what happend, but If I create the

    WebView webView = new WebView(Activity.this);
    

    it works. If I read the webview from activity with findViewById() it doesn't work.

    Also if you need to set a list of cookies that you received previously from a website. All you have to do is use a for-loop to go through and set all of them . It helped me to solve the situation

    0 讨论(0)
提交回复
热议问题