From e65cf6fa1f9b78e0abe2d2e156b6966318998f73 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Wed, 13 Apr 2022 12:13:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=86=85=E7=BD=AE=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=99=A8UA=E6=9C=AA=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/browser/WebViewActivity.kt | 11 ++++++++--- .../io/legado/app/ui/login/WebViewLoginFragment.kt | 3 +++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt b/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt index bac99cedf..96435e5fb 100644 --- a/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt +++ b/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt @@ -15,6 +15,7 @@ import androidx.webkit.WebSettingsCompat import androidx.webkit.WebViewFeature import io.legado.app.R import io.legado.app.base.VMBaseActivity +import io.legado.app.constant.AppConst import io.legado.app.databinding.ActivityWebViewBinding import io.legado.app.help.config.AppConfig import io.legado.app.help.http.CookieStore @@ -44,10 +45,11 @@ class WebViewActivity : VMBaseActivity() { binding.titleBar.title = intent.getStringExtra("title") ?: getString(R.string.loading) viewModel.initData(intent) { val url = viewModel.baseUrl - initWebView(url) + val headerMap = viewModel.headerMap + initWebView(url, headerMap) val html = viewModel.html if (html.isNullOrEmpty()) { - binding.webView.loadUrl(url, viewModel.headerMap) + binding.webView.loadUrl(url, headerMap) } else { binding.webView.loadDataWithBaseURL(url, html, "text/html", "utf-8", url) } @@ -68,7 +70,7 @@ class WebViewActivity : VMBaseActivity() { } @SuppressLint("JavascriptInterface") - private fun initWebView(url: String) { + private fun initWebView(url: String, headerMap: HashMap) { binding.webView.webChromeClient = CustomWebChromeClient() binding.webView.webViewClient = CustomWebViewClient() binding.webView.settings.apply { @@ -78,6 +80,9 @@ class WebViewActivity : VMBaseActivity() { useWideViewPort = true loadWithOverviewMode = true javaScriptEnabled = true + headerMap[AppConst.UA_NAME]?.let { + userAgentString = it + } } val cookieManager = CookieManager.getInstance() cookieManager.setCookie(url, CookieStore.getCookie(url)) diff --git a/app/src/main/java/io/legado/app/ui/login/WebViewLoginFragment.kt b/app/src/main/java/io/legado/app/ui/login/WebViewLoginFragment.kt index 54775b50d..c9feb1c4d 100644 --- a/app/src/main/java/io/legado/app/ui/login/WebViewLoginFragment.kt +++ b/app/src/main/java/io/legado/app/ui/login/WebViewLoginFragment.kt @@ -59,6 +59,9 @@ class WebViewLoginFragment : BaseFragment(R.layout.fragment_web_view_login) { binding.webView.settings.apply { builtInZoomControls = true javaScriptEnabled = true + source.getHeaderMap()[AppConst.UA_NAME]?.let { + userAgentString = it + } } val cookieManager = CookieManager.getInstance() source.loginUrl?.let {