Reputation: 8153
My question is pretty similar to Cookies & Webview - CookieSyncManager in Android!, but I really need to get the SystemClock.sleep()
time adjusted or another way to get setCookie
react immediately. Didn't work with 500ms, but worked with 5000ms, so it's not very reliable. Any way to loop sleep in onPageStarted
where I call sync
for CookieManager
after setCookie
?
My environment gets Cookie value from another server, so there is no session cookie here.
Thanks.
UPDATE:
Looks like Cookie handling is not working at all. I have following web flow:
WebView
again, and now getCookie
shows the session Cookie and loads page properlyUpvotes: 0
Views: 722
Reputation: 8153
I ended up calling setCookie
before I even have WebView
present in the application(I get the Cookie value from another server), also adding in WebViewClient
onPageStarted
and onPageFinished
the cookie sync, it seems to be working and I didn't have to cause sleep delays.
Upvotes: 1
Reputation: 355
Before calling webview.loadUrl(url), I add a while loop to detect whether the cookie of the url has been injected. If the cookie hasn't been asynchronously set, sleep for some time. Hope it helps.
while (!CookieManager.getInstance().hasCookies()
|| CookieManager.getInstance().getCookie(url)==null){
SystemClock.sleep(TIME_WAITING_FOR_COOKIE_SYNC);
}
webview.loadUrl(url);
Upvotes: 0