我检查了提供的链接、android 源代码、内部崩溃分析,似乎问题只存在于 android 4.0 - 4.0.4。我已经在 android 2.3.6、4.0.3、4.4.2 上测试了我的建议,它似乎是正确的。因此,我完成了针对此问题的以下解决方法:
package com.android.example;
import android.content.Context;
import android.os.Build;
public class WebViewUtil {
private static final String WEBVIEW_DATABASE_FILE = "webview.db";
public static boolean isWebViewCorrupted(Context context) {
try {
int currentSdk = Build.VERSION.SDK_INT;
if (currentSdk == Build.VERSION_CODES.ICE_CREAM_SANDWICH
|| currentSdk == Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
try {
context.openOrCreateDatabase(WEBVIEW_DATABASE_FILE, 0, null);
} catch (Throwable t) {
// try again by deleting the old db and create a new one
context.deleteDatabase(WEBVIEW_DATABASE_FILE);
context.openOrCreateDatabase(WEBVIEW_DATABASE_FILE, 0, null);
}
}
return false;
} catch (Throwable t) {
}
return true;
}
}