【问题标题】:Appcache on Android Webview not downloading sourcesAndroid Webview上的Appcache不下载源
【发布时间】:2012-10-04 22:49:14
【问题描述】:

我知道我的 web 应用程序的 appcache 运行良好,因为我在 Chrome 上尝试过它,即使在 Chrome for Android 上它也可以运行,但是从 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) 没有这样的表:CacheGroups 10-15 01:21:43.815: D/WebKit(14278): 错误: 10-15 01:21:43.815:D/WebKit(14278):应用程序缓存存储:未能执行语句“DELETE FROM CacheGroups”错误“没有这样的表: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) 没有这样的表:缓存 10-15 01:21:43.815: D/WebKit(14278): 错误: 10-15 01:21:43.815:D/WebKit(14278):应用程序缓存存储:未能执行语句“DELETE FROM 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) 没有这样的表:起源 10-15 01:21:43.815: D/WebKit(14278): 错误: 10-15 01:21:43.815: D/WebKit(14278): Application Cache Storage: failed to execute statement "DELETE FROM Origins" 错误 "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) 没有这样的表:DeletedCacheResources

显然 AppCache 无法正常工作 =/ 我做错了什么吗?谢谢!

【问题讨论】:

  • 这仍然困扰着我,我只是找不到方法来完成这项工作。有什么建议?谢谢:)
  • 只是猜测:尝试在setAppCacheMaxSize(1024*1024*16)setAppCachePath(appCachePath) 之前调用setAppCacheEnabled(true)。另外:你用的是哪个安卓版本?
  • @Alberto Elias 嗨,您是否设法找出缓存不起作用的原因?我有完全相同的问题

标签: android webview html5-appcache


【解决方案1】:

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

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

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

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

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

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

【讨论】:

    【解决方案2】:

    这些是适合我的设置:

    CookieSyncManager.createInstance(contextForDialog);
    webView = (WebView) findViewById(R.id.webView1);
    
    WebSettings settings = webView.getSettings();
    
    settings.setRenderPriority(RenderPriority.HIGH);
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    
    settings.setSaveFormData(true);
    settings.setLoadsImagesAutomatically(true);
    settings.setJavaScriptEnabled(true);
    settings.setDatabaseEnabled(true);
    settings.setDomStorageEnabled(true);
    settings.setAppCacheMaxSize(1024*1024*1024*8);
    String sDataPath = context.getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabasePath(sDataPath);
    settings.setAppCachePath(sDataPath);
    settings.setAllowFileAccess(true);
    settings.setAppCacheEnabled(true);
    settings.setAllowFileAccess(true);
    settings.setGeolocationEnabled(true);
    settings.setSavePassword(true);
    
    webView.setFocusable(true);
    webView.setFocusableInTouchMode(true);
    settings.setDatabaseEnabled(true);
    settings.setAllowContentAccess(true);
    settings.setLoadsImagesAutomatically(true);
    webView.addJavascriptInterface(this, "AndroidInterface");
    WebView.setWebViewClient(new routeNavClient());
    webView.setWebChromeClient(new webChromeClient());
    CookieManager c = CookieManager.getInstance();
    c.setAcceptCookie(true);
    

    【讨论】:

      猜你喜欢
      • 2012-06-28
      • 2015-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-18
      • 1970-01-01
      相关资源
      最近更新 更多