Android15系统适配

This commit is contained in:
syruan 2025-12-15 10:49:07 +08:00
parent 03d1c047d1
commit 8a03053c92
3 changed files with 73 additions and 6 deletions

View File

@ -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失效问题
*/

View File

@ -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);
}

View File

@ -35,17 +35,20 @@ public class WebViewConfigHelper {
// 启用数据库存储APIWebSQL
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