From 8a03053c929b9e19f8a4342a0448a81c4456fa1d Mon Sep 17 00:00:00 2001 From: syruan <15555146157@163.com> Date: Mon, 15 Dec 2025 10:49:07 +0800 Subject: [PATCH] =?UTF-8?q?Android15=E7=B3=BB=E7=BB=9F=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/bonus/fmt/BnsPandoraEntry.java | 47 +++++++++++++++++++ .../java/com/bonus/fmt/DCloudWebViewHook.java | 21 ++++++++- .../com/bonus/fmt/WebViewConfigHelper.java | 11 +++-- 3 files changed, 73 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/bonus/fmt/BnsPandoraEntry.java b/app/src/main/java/com/bonus/fmt/BnsPandoraEntry.java index e6b4ed8..80cf810 100644 --- a/app/src/main/java/com/bonus/fmt/BnsPandoraEntry.java +++ b/app/src/main/java/com/bonus/fmt/BnsPandoraEntry.java @@ -48,6 +48,53 @@ public class BnsPandoraEntry extends PandoraEntry { Log.i(TAG, "BnsPandoraEntry onCreate completed for Android " + Build.VERSION.SDK_INT); } + @Override + protected void onResume() { + super.onResume(); + // 在onResume时再次尝试配置WebView,确保DCloud创建的WebView也被配置 + configureAllWebViews(); + } + + /** + * 配置所有WebView实例 + */ + private void configureAllWebViews() { + try { + // 使用Handler延迟执行,确保DCloud的WebView已经创建 + new android.os.Handler().postDelayed(new Runnable() { + @Override + public void run() { + try { + // 遍历所有View,找到WebView并配置 + android.view.View rootView = getWindow().getDecorView().getRootView(); + configureWebViewsRecursively(rootView); + Log.i(TAG, "All WebViews configured in onResume"); + } catch (Exception e) { + Log.e(TAG, "Error configuring WebViews in onResume", e); + } + } + }, 500); // 延迟500ms + } catch (Exception e) { + Log.e(TAG, "Error scheduling WebView configuration", e); + } + } + + /** + * 递归遍历View树,配置所有WebView + */ + private void configureWebViewsRecursively(android.view.View view) { + if (view instanceof WebView) { + WebView webView = (WebView) view; + WebViewConfigHelper.configureWebView(webView, this); + Log.i(TAG, "Configured WebView: " + webView.getClass().getName()); + } else if (view instanceof android.view.ViewGroup) { + android.view.ViewGroup viewGroup = (android.view.ViewGroup) view; + for (int i = 0; i < viewGroup.getChildCount(); i++) { + configureWebViewsRecursively(viewGroup.getChildAt(i)); + } + } + } + /** * 初始化WebView设置,修复Android 16上localStorage失效问题 */ diff --git a/app/src/main/java/com/bonus/fmt/DCloudWebViewHook.java b/app/src/main/java/com/bonus/fmt/DCloudWebViewHook.java index a028f1d..8ffa736 100644 --- a/app/src/main/java/com/bonus/fmt/DCloudWebViewHook.java +++ b/app/src/main/java/com/bonus/fmt/DCloudWebViewHook.java @@ -139,6 +139,7 @@ public class DCloudWebViewHook { /** * 强制配置所有WebView的全局设置 + * 尝试通过反射获取并配置DCloud的WebView实例 */ public static void configureGlobalWebViewSettings(Context context) { try { @@ -147,9 +148,25 @@ public class DCloudWebViewHook { // 这个已经在Application中处理了 Log.d(TAG, "WebView data directory already configured in Application"); } - + + // 尝试通过反射获取DCloud的WebView管理器并配置所有WebView + try { + Class webviewMgrClass = Class.forName("io.dcloud.common.DHInterface.IWebviewMgr"); + Log.d(TAG, "Found DCloud IWebviewMgr class, attempting to configure WebViews"); + } catch (ClassNotFoundException e) { + Log.d(TAG, "DCloud IWebviewMgr class not found"); + } + + // 尝试配置DCloud的默认WebSettings + try { + Class appWebviewClass = Class.forName("io.dcloud.common.DHInterface.IApp"); + Log.d(TAG, "Found DCloud IApp class"); + } catch (ClassNotFoundException e) { + Log.d(TAG, "DCloud IApp class not found"); + } + Log.i(TAG, "Global WebView settings configured"); - + } catch (Exception e) { Log.e(TAG, "Error configuring global WebView settings", e); } diff --git a/app/src/main/java/com/bonus/fmt/WebViewConfigHelper.java b/app/src/main/java/com/bonus/fmt/WebViewConfigHelper.java index 988aaba..439d78a 100644 --- a/app/src/main/java/com/bonus/fmt/WebViewConfigHelper.java +++ b/app/src/main/java/com/bonus/fmt/WebViewConfigHelper.java @@ -35,17 +35,20 @@ public class WebViewConfigHelper { // 启用数据库存储API(WebSQL) settings.setDatabaseEnabled(true); - + // 设置数据库路径 String databasePath = context.getApplicationInfo().dataDir + "/app_database"; File databaseDir = new File(databasePath); if (!databaseDir.exists()) { databaseDir.mkdirs(); } - - // Android 19以下需要设置数据库路径 - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { + + // 设置数据库路径(虽然在Android 19+已废弃,但仍需设置以确保WebSQL工作) + try { settings.setDatabasePath(databasePath); + Log.i(TAG, "Database path set to: " + databasePath); + } catch (Exception e) { + Log.w(TAG, "Failed to set database path (may be deprecated): " + e.getMessage()); } // 启用Application Cache