I use a standard android.webkit.Webview
in a Java-Based native android app.
Inside the Webview the User logs into a webapp. After successful login the webapp stores a cookie with the access token. I want to access this cookie.
The cookie has the following characteristics:
- HTTPS Url Structure like:
https://api.example.com
httpOnly
FlagSecure
Flag
When on Android API Level 29 or API Level 30, calling CookieManager.getCookie("https://api.example.com")
works like expected and returns a String containing the Value of the Cookie.
When on Android API Level 28 or lower, calling the same method always returns null
. Nevertheless calling the CookieManager.hasCookies()
returns true
and the fact that the webapp in Webview
is working as expected shows that the cookie must exist somewhere.
I need to persist the cookie for handling "external" Downloads and other API Calls not executed within the Webview.
Why is this not working below API 28 and how can I solve it?
Things already tried:
- Calling the method
CookieManager.getCookie("https://api.example.com")
on different event hooks fromWebChromeClient
,WebViewClient
(e.g.onPageStarted
,onPageFinished
,onProgressChanged
,shouldInterceptRequest
,shouldOverrideUrlLoading
) - Flushing the cookies from memory to persistent storage using
CookieManager.flush()
in different places. - Extracting the cookie by intercepting traffic (this is too hacky using existing hooks)
Assumptions:
- Threading?, API Support below 28 incomplete?