android - Android Webview 上的 Appcache 不下载源

标签 android webview html5-appcache

我知道我的网络应用程序的应用程序缓存运行良好,因为我已经在 Chrome 上尝试过它,即使在 Android 版 Chrome 上它也可以运行,但是当从 WebView 将它加载到我的 Android 应用程序中时却没有。我有以下设置:

    myWebView = (WebView) v.findViewById(R.id.webView);
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setDomStorageEnabled(true);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setSupportMultipleWindows(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setAppCacheMaxSize(1024*1024*16);
    String appCachePath = getActivity().getApplicationContext().getCacheDir().getAbsolutePath();
    webSettings.setAppCachePath(appCachePath);
    webSettings.setAllowFileAccess(true);
    webSettings.setAppCacheEnabled(true);
    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
    webSettings.setDatabaseEnabled(true);
    String databasePath = "/data/data/" + getActivity().getPackageName() + "/databases/";
    webSettings.setDatabasePath(databasePath);
    webSettings.setGeolocationEnabled(true);
    webSettings.setSaveFormData(true);

但是在加载应用程序时,在 logcat 中我可以阅读以下内容

10-15 01:21:43.815: E/SQLiteLog(14278): (1) no such table: CacheGroups 10-15 01:21:43.815: D/WebKit(14278): ERROR: 10-15 01:21:43.815: D/WebKit(14278): Application Cache Storage: failed to execute statement "DELETE FROM CacheGroups" error "no such table: CacheGroups" 10-15 01:21:43.815: D/WebKit(14278): external/webkit/Source/WebCore/loader/appcache/ApplicationCacheStorage.cpp(558) : bool WebCore::ApplicationCacheStorage::executeSQLCommand(const WTF::String&) 10-15 01:21:43.815: E/SQLiteLog(14278): (1) no such table: Caches 10-15 01:21:43.815: D/WebKit(14278): ERROR: 10-15 01:21:43.815: D/WebKit(14278): Application Cache Storage: failed to execute statement "DELETE FROM Caches" error "no such table: Caches" 10-15 01:21:43.815: D/WebKit(14278): external/webkit/Source/WebCore/loader/appcache/ApplicationCacheStorage.cpp(558) : bool WebCore::ApplicationCacheStorage::executeSQLCommand(const WTF::String&) 10-15 01:21:43.815: E/SQLiteLog(14278): (1) no such table: Origins 10-15 01:21:43.815: D/WebKit(14278): ERROR: 10-15 01:21:43.815: D/WebKit(14278): Application Cache Storage: failed to execute statement "DELETE FROM Origins" error "no such table: Origins" 10-15 01:21:43.815: D/WebKit(14278): external/webkit/Source/WebCore/loader/appcache/ApplicationCacheStorage.cpp(558) : bool WebCore::ApplicationCacheStorage::executeSQLCommand(const WTF::String&) 10-15 01:21:43.815: E/SQLiteLog(14278): (1) no such table: DeletedCacheResources

显然 AppCache 不工作 =/我做错了什么吗?谢谢!

最佳答案

在appcache和domstore之前设置db, 在 set*Enabled() 之前设置任何“参数”,如 set*Path()/set*Size()

除此之外,如果在使用时将两个独立管理的缓存堆叠在一起可能不是一个好主意

getActivity().getApplicationContext().getCacheDir().getAbsolutePath()

作为 webview 的缓存管理器应该存储其数据的目录

当 Activity 的缓存管理器决定删除 webview 的缓存管理器创建的文件时,webview 的缓存管理器不会收到通知,可能会进一步依赖它的存在

可能会工作很长时间,但有一天它可能会变成一个难以识别的交替错误

关于android - Android Webview 上的 Appcache 不下载源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12887558/

相关文章:

php - 将文件加字符串从 android 上传到服务器不起作用

android - 未找到名称为 'default' 的配置

html - 本地存储可以被认为是安全的吗?

javascript - 当离线网络应用程序缓存失败时,有效的后备措施是什么?

php - 我可以使用 Manifest 或 Appcache 文件定位特定的浏览器/设备,或者只是从桌面浏览器中排除 appcache 吗?

android - 将 parent 用于可绘制资源

android - 用于在 android 中设置 actionbarsherlock 的最小 SDK

android - 如何获取android webView中的触摸事件信息?

javascript - "Chrome Apps"webview.executeScript 访问guest全局变量

半屏 Android 网页 View