Cookie在Android的WebView中无法正常工作 [英] Cookie doesn't work properly in webview in android
问题描述
所需的数据不会立即在WebView中写入cookie。但是,当我等待10-15秒时,一切正常。
为了说明这种情况,此示例对我而言将是很好的:
Needed datas is not written to cookies immediately in WebView. But when I wait for 10-15 seconds everything is ok. To explain the situation, this example would be good as for me:
我打开应用程序并登录。登录后,我立即关闭该应用程序。然后,在我再次打开该应用程序之后,它显示我要注销。但是,如果我在1分钟后打开该应用程序,它将再次显示为已登录。对我来说,cookie是最近写入的。但是我找不到解决办法。如果您知道的话,请帮助我。
I open the app and login. After login, I close the app immediately. Then after I open the app again, it shows me to logout. But if I open the app after 1 minute, it shows again as logged in. For me cookies are written lately. But I cannot find solution. Please help me if you know.
我使用过CookieManager类,但它也无济于事。
I used CookieManager class but it doesn't help either.
CookieManager.getInstance().setAcceptCookie(true);
推荐答案
我遇到了类似的问题,并添加了以下代码并
I had similar issue and I added the below code and worked.
String myURL = "https://www.yourWebPage.com";
android.webkit.CookieManager cookieManager = android.webkit.CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
cookieManager.acceptCookie();
cookieManager.setAcceptFileSchemeCookies(true);
cookieManager.getInstance().setAcceptCookie(true);
cookieManager.getCookie(myURL);
希望有帮助。
这篇关于Cookie在Android的WebView中无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!