问题
It is possible to achieve this currently in Android? I only can find deprecated questions about old methods (CookieSynchManager) which not seems to work for this actually.
It is possible to achieve it? can't find anything also on the android developers guide.
Thank you
回答1:
Having the same problem...I solved reading the doc here:
https://developer.android.com/reference/android/webkit/CookieSyncManager
For future readers: to force the Cookie sync process you can manually call the flush() method of CookieManager
I personally put in webview the following code:
public class MyWebViewClient extends WebViewClient {
public void onPageFinished(WebView view, String url) {
CookieManager.getInstance().setAcceptCookie(true);
CookieManager.getInstance().acceptCookie();
CookieManager.getInstance().flush();
}
}
回答2:
Since CookieSynchManager is deprecated, CookieManager.getInstance() is the CookieManager instance for your entire application. Hence, you enable it by
CookieManager.getInstance().setAcceptCookie(true)
setAcceptCookie(boolean accept);
Sets whether the application's WebView instances should send and accept cookies.
https://developer.android.com/reference/android/webkit/CookieManager.html
来源:https://stackoverflow.com/questions/45751626/how-to-persist-webview-cookies-between-app-executions