feat: per-app UA config, fix demo file path and back-loop
This commit is contained in:
@@ -31,10 +31,18 @@ class WebViewManager(private val activity: Activity) {
|
||||
// (lifecycle is managed by the host); transparent background so a webapp without
|
||||
// a declared background shows the wallpaper instead of a default white
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
fun createContentWebView(): WebView {
|
||||
fun createContentWebView(ua: String?): WebView {
|
||||
val webView = WebView(activity)
|
||||
webView.setBackgroundColor(Color.TRANSPARENT)
|
||||
configure(webView)
|
||||
// UA 解析:desktop/pc → PC UA;自定义字符串 → 直接用;null → 默认平板 UA
|
||||
// UA resolution: desktop/pc -> desktop UA; custom string -> used as-is;
|
||||
// null -> default tablet UA
|
||||
webView.settings.userAgentString = when {
|
||||
ua == null -> UA_TABLET
|
||||
ua == "desktop" || ua == "pc" -> UA_DESKTOP
|
||||
else -> ua
|
||||
}
|
||||
return webView
|
||||
}
|
||||
|
||||
@@ -50,4 +58,15 @@ class WebViewManager(private val activity: Activity) {
|
||||
domStorageEnabled = true
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
// PC 版 UA(desktop/pc)
|
||||
private const val UA_DESKTOP =
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " +
|
||||
"(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
||||
// 安卓平板 UA(默认)
|
||||
private const val UA_TABLET =
|
||||
"Mozilla/5.0 (Linux; Android 13; SM-X700 Build/TP1A.220624.014) " +
|
||||
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user