Setting WebChromeClient and WebViewClient
Opened this issue · 1 comments
ArabAgile commented
I need to inject cookies and headers in each request. How possible it's using FinestWebView?
Also, I need to do something in shouldOverrideUrlLoading
, how to achieve this?
Cililing commented
About Cookies - you can do it via CookieManager. For example:
fun setWebViewSession(url: String, onSessionSet: (() -> Unit)?) {
doAsync {
// Refresh login data
...
// Build and execute request
...
val response = httpClient.newCall(request).execute()
// Obtain and sync cookies
val cookies = response.headers().values("Set-Cookie")
CookieSyncManager.createInstance(application)
CookieSyncManager.getInstance().startSync()
val cookieManager = CookieManager.getInstance()
cookieManager.removeAllCookie()
cookies.forEach {
cookieManager.setCookie(URL(url).host, it)
}
CookieSyncManager.getInstance().sync()
onSessionSet?.invoke()
}
}
This code snipped is about loggin user, that's why I make a request before setting cookies. For your purposes it should look fimilar.