Android15系统适配
This commit is contained in:
parent
03d1c047d1
commit
8a03053c92
|
|
@ -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失效问题
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -139,6 +139,7 @@ public class DCloudWebViewHook {
|
|||
|
||||
/**
|
||||
* 强制配置所有WebView的全局设置
|
||||
* 尝试通过反射获取并配置DCloud的WebView实例
|
||||
*/
|
||||
public static void configureGlobalWebViewSettings(Context context) {
|
||||
try {
|
||||
|
|
@ -148,6 +149,22 @@ public class DCloudWebViewHook {
|
|||
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) {
|
||||
|
|
|
|||
|
|
@ -43,9 +43,12 @@ public class WebViewConfigHelper {
|
|||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue