要在Android kotlin中处理Webview的cookies,您可以按照以下步骤:
val webview: WebView = findViewById(R.id.webview) val cookieManager: CookieManager = CookieManager.getInstance() cookieManager.setAcceptCookie(true) cookieManager.setAcceptThirdPartyCookies(webview, true) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { webview.settings.mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW }
val cookieName = "mycookie" val cookieValue = "some value" val cookieString = "$cookieName=$cookieValue; domain=url.com; path=/" cookieManager.setCookie("https://url.com", cookieString)
val url = "https://url.com" val cookie = cookieManager.getCookie(url)
以上是一种处理Webview cookies的方式,它使用了Android kotlin的一些基本操作,欢迎使用!