我试图使用切换按钮在移动网站和桌面网站之间进行切换,所以我设置了适当的user-agent
。但是一旦加载了桌面站点,便尝试通过设置移动用户代理并刷新Web视图来加载移动站点。它不起作用,但是如果我在搜索栏中再次输入该网站,则会加载正确的网站。
fun setMobileView(context: Context) {
val tinyDB = TinyDB(context)
getWebView()?.settings?.userAgentString = "Mozilla/5.0 (Linux; Android 7.0; SM-G930VC Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/58.0.3029.83 Mobile Safari/537.36"
getWebView()?.reload()
Log.d(TAG, "Setting mobile user agent")
tinyDB.putBoolean("is_desktop_view", false)
}
fun setDesktopView(context: Context) {
val tinyDB = TinyDB(context)
getWebView()?.settings?.userAgentString = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36"
getWebView()?.reload()
Log.d(TAG, "Setting desktop user agent")
tinyDB.putBoolean("is_desktop_view", true)
}